Launch Application

maxmangion

AWF VIP
Local time
Today, 08:35
Joined
Feb 26, 2003
Messages
2,805
I have a command button on a form, and on its onClick event i have placed the following statement in order to open a specific word document:

Code:
Call Shell("C:\Program Files\Microsoft Office\Office 10\Winword.exe C:\Temp\Test.doc", vbMaximizedFocus)

This works fine, however I noticed that if the path for the specific document contains a space, it does not open up successfully but i get a msgbox saying "the document name or path are not valid"

Any suggestions please ?

Thank You
 
This subject has been debated before in a few other threads. I normally use an OpenFile API.

Check out the OpenFile function in my Browse [Find a directory or file] sample. It will allow you to select any file and open it.

Here is how you would use it and file/directory names with spaces are no problem with the OpenFile API. Put this in a public module and run the test function at the bottom.

Code:
Option Compare Database
Option Explicit

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)
On Error GoTo Err_OpenFile

    OpenFile = ShellExecute(Application.hWndAccessApp, "Open", sFileName, "", "C:\", 1)

Exit_OpenFile:
    Exit Function

Err_OpenFile:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_OpenFile

End Function

Public Function TestOpeningFile()
On Error GoTo Err_TestOpeningFile
    
    Dim Y As String
    Dim Z As String
    
    Y = "C:\Temp\Testing 1 2 3\"
    Z = "Test File.xls"
    
    OpenFile Y & Z
    AppActivate Z, True
    
Exit_TestOpeningFile:
    Exit Function
    
Err_TestOpeningFile:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_TestOpeningFile
    
End Function
 
Thank you for your tip. it worked perfect.
 
on using the above code (which works fine), i notice that if for instance i will open a word document, although it opens fine, and it appears on the screen, it seems that the document does not get the focus on itself, becuase the title bar at the top shows in dimmed colour.

Is there any way in which i can insert a vbMaximizedFocus (or something similar) in the above code ?

Thanks
 
i've managed to sort out the problem. Instead of using the above code, i simply used

Application.FollowHyperlink filename

It is working ok.
 
maxmangion said:
on using the above code (which works fine), i notice that if for instance i will open a word document, although it opens fine, and it appears on the screen, it seems that the document does not get the focus on itself, becuase the title bar at the top shows in dimmed colour.

Is there any way in which i can insert a vbMaximizedFocus (or something similar) in the above code ?

Thanks
I am not able to duplicate the unfocused problem you mention.
 
Never knew about Application.FollowHyperlink !! It worked like a charm, for any type of file. This really simplify my usual way of opening files.
 

Users who are viewing this thread

Back
Top Bottom