________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'If we're supposed to work in Hex, why have we only got A fingers?'
Forget Shell. You need to use ShellExecute to open any document with it's default app. eg. PDF with Acrobat Reader, .DOC with Word, .htm with IE etc.
This is the way I do it. There are neater ways, but I'm just Copy/Pasting from existing code.
In a module (.BAS), place all of this:
'************************
Option Explicit
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private 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
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10
Private Const SE_ERR_NOASSOC As Long = 31
Public Sub RunShellExecute(sTopic As String, _
sFile As Variant, _
sParams As Variant, _
sDirectory As Variant, _
nShowCmd As Long)
Dim hWndDesk As Long
Dim success As Long
'the desktop will be the
'default for error messages
hWndDesk = GetDesktopWindow()
'This is optional. Uncomment the three lines
'below to have the "Open With.." dialog appear
'when the ShellExecute API call fails
If success = SE_ERR_NOASSOC Then
Call Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " & sFile, vbNormalFocus)
End If
End Sub
'*********************************
Create a form, place a button called Command1 on it and paste in this code into the declarations area:
'*********************************
Dim startpath As String
Dim sTopic As String
Dim sFile As String
Dim sParams As Variant
Dim sDirectory As Variant
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.