I want to create a batch script that will take a .csv file that is tagged with a time stamp in the name open it, then open a specific macro-enabled Excel file (which will always be the same) and then run the macro in the 2nd workbook effective for the first workbook only.
So example:
BATCH:
for %%f in (PATH\*.csv) do ("C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE" "%%f")
I have this line to account for the changing time stamp
then the batch continues:
call PATH\Macro.xlsm
The CMD seems to stall after the first part and will not call the second file.
If I can have this open both files, can the macro run for all open workbooks rather than just the one it's built in via batch?
Any help would be appreciated as I am very new to this.
Related
I have a file which changes daily in a folder - but retains the same name so I can get SSIS to open that file without a problem. Because the file changes daily - the Macro needed to process it is resident in the System.XLSB workbook. How do I open the target file called Source.xls for arguments sake then trigger the Formatting macro in the SYSTEM.XLSB file to perform the actions on it? Any help greatly appreciated.
I have .csv files with different filenames put on a shared drive twice a day.
I need to apply a macro I wrote, (with much help) to the most recently created file with no user input so I can add it to Windows Task Scheduler.
For the task scheduler part I was going to use a PowerShell script.
How do I have Excel open a macro from file1 and run it on file2, where the filename on file2 changes daily?
I would recommend to store your macro in Personal Macro Workbook. With that you can run it on every excel file you open.
Here is how you do it:
https://support.office.com/en-us/article/create-and-save-all-your-macros-in-a-single-workbook-66c97ab3-11c2-44db-b021-ae005a9bc790
Does anyone know what registry keys need to be modified in order to open macro enabled excel files in a separate instance of Excel (ie: separate windows)?
I followed the instructions on the following pages Microsoft How-To (if you want to open *.xlsx files in separate instances of excel)
and relation between registry folders and file extensions. The 'Microsoft How-To' link worked nicely and did exactly what it was supposed to do. However, I need xlsm files to open in separate windows and for the xlsx files to continue to open the default way (all in the same window/excel-instance).
I thought if i modified the Excel.SheetMacroEnabled.12\shell\open data (similar to what is described in the first link) the *.xlsm files would then always open in a new window each time.
Instead of this working successfully, now when I try to open an *.xlsm file, a blank excel window comes up with no workbook in it (after this failed attempt I imported the original settigs back so everything was restored).
Figure: I believe one of the folders shown in the image below has the key which needs to be changed in order to open excel macro files in separate windows.
You also need to delete the command REG_MULTI_SZ (the one with the seemingly gibberish-cryptographic value). Backup it in case it goes wrong!
Then, the XLSM files will open in a separate Excel program (notice the brief splash screen, which only appears when a new instance of Excel is created).
But be careful! In my tests, the order in which you open the file types make a big difference!
For example, if there is an Excel instance with a XLSM file open, and you open a XLSX file, it will try to reuse the existing Excel instance, because the registry associated to Excel.Sheet.12 tells it to do it no matter the file type already open. Only XLSM files opened after an existing Excel instance is running will create its own instance of Excel.
I will search for a workaround, but I think this is enough for you to start the tests in your computer.
I have an excel workbook open and I want a .bat file to open a workbook within that same instance of excel. How do I do it? In other words, an excel workbook is already open in one instance of excel and I want to open another workbook with a .bat file script, but I do not want to create another instance of excel. Both workbooks should be open in the same instance of excel.
Here is what I am doing now, which doesn't work:
Excel workbook 1 is already open (manually), instance 1 of excel (excel.exe) is already open (manually). At some point later in time my .bat file starts running via Task Scheduler. My .bat file code looks like this:
REM open excel workbook
"C:\Program Files (x86)\Microsoft Office\Office14\Excel.exe" "Y:\somepath\somefilename.xlsm"
EXIT
...and instance 2 of excel.exe is created with "somefilename" open in it, which is wrong.
I need just one instance of excel.exe and both files/workbooks open in that one instance and I have to open the second file with a .bat file (for reasons that are frustrating, but necessary). No other languages, just batch please. Thanks!
MC ND's comment on my original question is correct:
start "" "Y:\somepath\somefilename.xlsm"
...works perfectly.
I want to create a batch file which when I run this file, an excel file should open with some columns in it.
Say if I click on batch file, excel file with columns name, project, ID should also get included in excel file.
Also with this a macro should be open.
Please help. I dont have any idea about this.
I don't think it is possible to automate excel with pure batch.
Why not:
Create an "template" excel file with the default columns and macro included
Have a batch file copy this template (copy template.xslx newfile.xslx) file and open it (`Start newfile.xslx).
For the new file, you'd either have to generate a random or timestamp-based name or have the user enter the name before making a copy.