Don't ask me to explain the code below...I just know that it works.
The original can be found at http://xcelfiles.homestead.com/Exce...
Any comment lines that start with 2 single quotes ('') are lines that I either added, modified or commented out to make the code work with PDF documents. Please refer to the original code to see the differences.
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
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Const SW_SHOWNORMAL = 1
Const SE_ERR_NOASSOC = 31
Const ERROR_FILE_NOT_FOUND = 2&
Const WM_CLOSE = &H10
Sub OpenAnyFile()
Dim strVisio As String
''I added the next line
Dim strPDF As String
Dim strChm As String
Dim strMail As String
Dim lngRet As Long
Dim Msg As String
'// //
'// Example strings //
'// //
'// Open a Visio File
''strVisio = "C:\VisioFiles\WIP\MyDrawing.VSD"
'// Open a chm Help file
''strChm = "C:\WINDOWS\HELP\msoe.chm"
'// Open up default Mailer
''strMail = "mailto:ivanmoala@xtra.co.nz"
'
'// Note: You don't have to specify the "open" command
'// by default Shell will default to open if you use
'// vbNullString, "Open" is just used for clarity.
'' I added the next line and replaced strChm with strPDF in the "lngRet ="section
strPDF = "C:\Documents and Settings\My_Account\Desktop\MFS.pdf"
lngRet = ShellExecute( _
0, _
"Open", _
strPDF & vbNullString, _
vbNullString, _
vbNullString, _
SW_SHOWNORMAL)
Select Case lngRet
Case SE_ERR_NOASSOC
Msg = " is NOT Associated with any Application!"
Case ERROR_FILE_NOT_FOUND
Msg = " could NOT be found!"
End Select
'' I commented out the next line...don't know why the author wants to display the lngRet value.
''MsgBox lngRet
SendMessage lngRet, WM_CLOSE, 0, 0
If Len(Msg) = 0 Then Exit Sub
MsgBox strVisio & Msg
End Sub