Search code examples
windowsexcelbatch-fileapplication-restartvba

Open multiple Excel files in separate instances with batch file


I run multiple Excel instances / files which require a manual PC restart daily. Currently I save all my Excels, restart the PC, then have to open each file separately, which is quite manual. Is anyone aware of a program I can run that will open the same Excel files in separate Excel instances after reboot?

Solution:

@echo off
setlocal EnableDelayedExpansion
set "excel=C:\Program Files (x86)\Microsoft Office\Office12\Excel.exe"
for %%a in (
 "R:\Other Stuff\Name\text_excel_1.xlsx"
 "R:\Other Stuff\Name\text_excel_2.xlsx"
) do start "" "%excel%" "%%~a"

Previous Edits:

I've gotten this far with a batch BUT the second Excel instance won't open unless I close the first.

"C:\Program Files (x86)\Microsoft Office\Office12\Excel.exe"
"C:\Program Files (x86)\Microsoft Office\Office12\Excel.exe"
"C:\Program Files (x86)\Microsoft Office\Office12\Excel.exe"

Has anyone see this before?

EDIT: have tried using the start command, but this opens the both files in the same instance. How would I go about opening them in multiple instances?

start /d "R:\Other Stuff\Name" test_excel_1.xlsx
start /d "R:\Other Stuff\Name" test_excel_1.xlsx

EDIT 2:

R is a share drive; this opens multiple Excel instances but can't find the files. Do I need to modify for network drives? But I was able to open them using the start /d command which is a tad puzzling for me.

@echo off
setlocal EnableDelayedExpansion
set "excel=C:\Program Files (x86)\Microsoft Office\Office12\Excel.exe"
for %%a in (
 "R:\Other Stuff\Name\text_excel_1.xlsx"
 "R:\Other Stuff\Name\text_excel_2.xlsx"
) do start "" "%excel%" "%%~a"

Error is now:

'R:\Other Stuff\Name\test_excel_2.xlsx' cannot be found. Checking spelling or try a different path.

Does anyone see anything wrong with this? start /d finds the file but the code starting with @echo off does not find the file.


Solution

  • to open all xlsx files in current folder with excel:

    for %%a in (*.xlsx) do start "" "%%a"
    

    (for use on command line, replace every %%a with %a)

    To open every file in a separate EXCEL instance:

    @echo off
    setlocal EnableDelayedExpansion
    set "excel=C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE"
    for %%a in (
     "R:\Other Stuff\Name\Document1.xls"
     "C:\users\JSNoob\documents\my Passwords.xlsx"
    ) do start "" "%excel%" "%%~a"
    

    (adapt the excel path to fit your system and add the files, you need)