Open more than one file in excel

vipersmind

it can't be!
Local time
Tomorrow, 07:40
Joined
Dec 26, 2002
Messages
82
Hi
I would like to be able to open multiple files in excel.
The user has the option, after exporting the tables, to view them in excel. I have the following code behind a command button which open one of the files.

PHP:
Private Sub OpenVulcanWorkFiles_Click()
Dim oApp As Object

Set oApp = CreateObject("Excel.Application")
oApp.Visible = True

With oApp
.workbooks.Open "G:\Underground\Geology\Vulcan_Work\pgmug\VulcanHeader.csv"

If Err Then
Shell "C:\Program Files\Microsoft Office\Office\" & "Excel/Automation", vbMaximizedFocus

AppActivate "Microsoft Excel"
End If

Set oApp = Nothing

End With

End Sub

I would like to be able to Open all three files at once
VulcanHeader.csv
VulcanSurvey.csv
VulcanSample.csv

thanks:D
 
If Excel is a registered app on the workstation and if all you want to do is open the file and don't need to do anything special with it you can actually eliminate all of the code your trying to use and just repeat the shell command like you already have for each file
Code:
Private Sub OpenVulcanWorkFiles_Click()
    Shell "excel.exe VulcanHeader.csv", vbNormalFocus
    Shell "excel.exe VulcanSurvey.csv", vbNormalFocus
    Shell "excel.exe VulcanSample.csv", vbNormalFocus
End Sub
You will need to insert your path infront of the filenames.
 
Last edited:
Thanks Calvin

I got rid of most of the code as you suggested.
The only problems now it ends up opening 3 different instances of excel, one for each file.
This would be fine but I have a hidden file in excel containing a heap of macros and this file is set to open first when you open excel. If you open more than one instance of excel then the macro file is set to locked.
I need to open all of the files in the one instance of Excel
Any further suggestions would be great

PHP:
Shell "excel.exe g:\underground\geology\vulcan_work\pgmug\VulcanHeader.csv", vbNormalFocus
    Shell "excel.exe g:\underground\geology\vulcan_work\pgmug\VulcanSurvey.csv", vbNormalFocus
    Shell "excel.exe g:\underground\geology\vulcan_work\pgmug\VulcanSample.csv", vbNormalFocus
 
Last edited:
In that case use just one Shell statment and separate each file and path with a space.
Code:
Shell "excel.exe c:\book1.xls c:\book2.xls c:\book3.xls", vbNormalFocus
 
perfect

Thanks Again Calvin

Exactly what I was after

Cheers
Cress
 

Users who are viewing this thread

Back
Top Bottom