Really Simple Question (Hopefully!)

jennilewis

Registered User.
Local time
Today, 16:07
Joined
Aug 11, 2005
Messages
16
I am trying to get VBA to open an excel spreadsheet. It is perfectly happy when I use a file with a pathname that doesn't contain any spaces but when i try and open a file from e:\common files it won't work.
I'm sure this is really simple but I just can't work out how to make it open!
Thanks
 
Try this function.
Code:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Function OpenFile(sFileName As String)
OpenFile = ShellExecute(Application.hWndAccessApp, "Open",sFileName, "", "e:\common files", 1)
End Function

On the Onclick button
Code:
OpenFile ("YourFileName.xls")

Hope it helps.
 
Last edited:
Not quite sure where I am supposed to put that! My VBA knowledge is very basic!

I currently have:

Private Sub Command25_Click()
On Error GoTo Err_Command25_Click

Dim stAppName As String

stAppName = "excel.exe E:\Common files\Database\non"
Call Shell(stAppName, 1)

Exit_Command25_Click:
Exit Function

Err_Command25_Click:
MsgBox Err.Description
Resume Exit_Command25_Click

End Function
 
Maybe:

stAppName = "excel.exe 'E:\Common files\Database\non'"

???
 
Ken, Your routines brings up two copies of the extension as in
"E:\Common files\Database\non\YourFileName.xls.xls"



Private Sub Command25_Click()
On Error GoTo Err_Command25_Click

Dim stAppName As String

stAppName = "excel.exe E:\Common files\Database\non\YourFileName.xls"
Call Shell(stAppName, 1)

Exit_Command25_Click:
Exit Function

Err_Command25_Click:
MsgBox Err.Description
Resume Exit_Command25_Click

End Function
 
Grrrr, this worked yesterday but today it says it expects a variable or procedure not a module
 
Where is the error tracked to.
 
Maybe:

stAppName = "excel.exe 'E:\Common files\Database\non\mySpreadsheet.xls'"

or:

stAppName = "c:\Myexcelpath\excel.exe 'E:\Common files\Database\non\mySpreadsheet.xls'"

or just:

stAppName = "'E:\Common files\Database\non\mySpreadsheet.xls'"

??? :confused:
 
Searching the forum is a great way to find the answers to your questions. :D

I have a working example of the ShellExecute function in my Browse [Find a directory or file] sample. It will demonstrate how to open a selected file and a lot more.
 

Users who are viewing this thread

Back
Top Bottom