Windows batch command question, start excel temp.xls - windows

I wanted to know that if I do
start excel temp.xls
The os will start a new excel instance and open the workbook temp.xls in that instance, AS AN ATOMIC action.
Right now what I have is
start excel
start temp.xls
And most often these two command will mess up my other excel instance, ie, opening temp.xls in another excel instance that has another workbook already opened.
Thanks,

While I think that "start excel temp.xls" will open temp.xls in the Excel instance started by start, you'd be on the safe side, if you use
"<PathToExcel>excel" [/<opt>] "<PathToXls>temp.xls"
For opt see cli for excel (pick the docs for your version).

The Command-line switches for Excel 2007 document explains the switches:
You can change certain aspects of how
the program starts by adding
subcommands called switches to the
Excel.exe command. A switch appears as
a space after the main command,
followed by a slash mark (/) and the
name of the switch. The switch is
sometimes followed by another space
and then one or more specific
instructions called parameters, which
give the program further information
about how to execute the Excel.exe
command.
In your case you do not use a switch but a parameter. It is used to give the program further information about how to execute the Excel.exe command.
Parameter: file name
Description: starts Excel and opens the specified file.
So I would assume that the parameter is bound to the excel instance started.

Related

A question about Power Automate to proceed macro from another excel file

Hello I am a newbie that working on a project that requires to use Power automate desktop to analyze data in the excel worksheet. The project needs me to download a excel file from website and proceed with macro. Now I am able to download file from website and macro script has been tested without problem. So here comes the problem, I couldn't figure out how to use power automate to run macro from another excel file.
So let's say there are two excel file a.xlsm and b.xlsm and both store in download folder. The a.xlsm will always been the download file from website and b.xlsm will be the file that I already store the macro. I need to open a.xlsm and run the macro store in b.xlsm. Thanks for any suggestion in advance.
Ok I figure it out, here is the step you may follow.
Record Macro
Stop recording the Macro
Click Macros under developer section (or press Alt + F11)
Find the Module 1 under VBAProject (PERSONAL.XLSB (Default name))
Copy your finished script and paste into the module1
In the run excel macro function in Power Automate Desktop, put that code after Macro: 'PERSONAL.XLSB'!**** (**** will be the macro function you want to run)
note: please remember every time you want to run the macro you have to open the original worksheet which contains the macro, otherwise you won't be able to run it

Can a Windows batch file determine its own window name?

When a Windows batch file is launched via a shortcut (from the Start Menu, for example), its window will typically receive the title of the shortcut.
Is it possible for the batch file to determine the name of its own window?
This question is related to Can a Windows batch file determine its own file name?, but that question asks if the batch file can determine its own filename. I am asking if a batch file can determine its own window name.
StackOverflow user QcFe lent a kind hand by finding this QA on Superuser: https://superuser.com/questions/1155853/how-to-get-the-window-title-text-from-batch-file
The short answer is that Windows provides no simple and direct way for batch files to accomplish this task.
Windows provides the internal title command to set the window title, but no way to retrieve it. (Which is disappointing, because it would be such a simple addition to the title command.)
The functionality can be attained using PowerShell or possibly tasklist, but for the latter, there are issues that need to be addressed if there are more than one command shell window open.
I elected to force the window to have a unique name using the Title command. That way I could reference it correctly for tools that need to know the window title, such as NirSoft's excellent nircmd utility.

How to comfortably monitor variables in a VBscript during development process? (e.g. in a continuously opened command window)

I need to write a huge VBscript to automatically run an application and I'm looking for a way to comfortably monitor what I'm actually doing, in other words, to display the values of some/all variables involved in my script.
I'm used to work with Matlab, where I have a comfortable workspace browser. When I run a Matlab script, all variables, their types and their values are accessible in that workspace and can be checked.
The VBscript I write with Notepad++ (it needs to be a free editor) and the only way I found to display variables was echoing them via wscript and cscript.
I set up the shortcuts.xml with the following line to run my script directly from Notepad++:
<Command name="Run with CScript" Ctrl="yes" Alt="no" Shift="yes" Key="116">cmd /K %windir%\system32\cscript.exe "$(FULL_CURRENT_PATH)"</Command>
In case I include commands in my script like
Wscript.Echo myVar
Wscript.Echo "Hello World!"
and run it with the newly introduced shortcut, a cmd window pops up and displays the value of myVar and "Hello World!".
But the next time I run the script a new window pops up. So my question is:
Is it possible get a continuously opened output window, displaying all echoed values everytime I run a script? I actually want to put the window on a second screen and keep the values from previous runs. So I can enter a line Wscript.Echo something, run, check, enter something else and so on, without fiddling around with a bunch of opened windows.
Alternatively, is there any open-source/free editor which offers an accessible workspace like the one in Matlab?
The open-source editor SciTE offers what I was looking for.
The default settings in vb.properties enable a similar behavior like in Notepad++
command.build.$(file.patterns.wscript)=cscript "$(FilePath)"
command.build.subsystem.$(file.patterns.wscript)=1
One can change it as follows to get the output into the integrated console.
command.go.$(file.patterns.wscript)=cscript.exe //nologo "$(FilePath)"
command.go.subsystem.$(file.patterns.wscript)=0
F5 runs the script and Shift+F5 cleans the output.
Another option is the NppExec Plugin for Notepad++ suggested by #Ansgar Wiechers, which adds a console. The script can be run with cscript.exe /nologo "$(FULL_CURRENT_PATH)" then.
Use a debugger. Start your script with the (meta)option //X. If you are lucky, you already have installed software (MS Office, Visual Studio (Express)) that provides a debugger for VBScript. If not do a bit of research to find an Express version suitable to your OS.
You can almost write native VBScript in the VBA editor, so if you have Excel or whatever you can use this to debug, then go through some steps to convert back to VBScript. That's what I usually do.

VB script to open .exe file and perform 4 activities

I have a tool based on .net. I need a vb script which would open this tool (.exe file) and then select 3 radio buttons, click on a button to browse a xml file stored in same folder and then click on invoke button. Is this possible? I am a complete fresher and just have this idea in mind for an automation. This is required as I have to perform the same steps daily.
I could find this code:
CreateObject("WScript.Shell").Run("""C:\Users\abc\Desktop\folder\Tool.exe""")
Which is doing my task to open the .exe file perfectly. Can someone help/guide me in achieving the further steps?
You might be better off making your tool work via the command line and having it accept arguments.
That way, you could use a .bat file to call your 'tool' passing in the arguments it needs and away you go.
These should get you started on your quest.
Creating a HelloWorld Console Application Using VisualBasic.NET
How to Parse Command Line Parameters?
What is a bat file

Need to write a shell extension

I need to write a shell extension for a small context menu.
unfortunately i reused the code available in open source which uses .net 4.0
now the problem is the requirement is I shud not use .NET 4.0.
Instead is there a way where in I can make an entry in the registry so that the shell extension pops out
My requirement is ....
1. The shell extension context menu should display only on .txt, .csv, .xls files.
2. Upon click of shell extension I need to start a different process, by passing the full name of the file on which we click as parameter to the process.
If you just want to add items to the context menu for certain file types, and in response launch an external application, you don't need to write a shell extension. Registry entries are enough to express this.
As the http://www.jfitz.com/tips/rclick_custom.html article you linked to says, for each file type you want to act on, you need to add a new registry key under the Shell subkey, then create a subkey called command, whose value is the name of the application to launch.
To pass the name of the file you clicked on to this external application, add "%1" to the command. Include the quotes, so that if the file's name contains spaces, it will still be treated as one token by the receiving program.

Resources