Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a PDF file from GetOpenFileName

Status
Not open for further replies.

Pudsters

Technical User
Mar 16, 2006
151
US
I can open Excel and Word Documents from the following routine but I don't know how to open a pdf file. Any help?


Sub OpenFile()
Dim fn As Variant

ChDir "C:\Program Files\FolderName"
fn = Application.GetOpenFilename("All files,*.*,Excel-files,*.xls,Word Files,*.doc,PDF Files,*.pdf,", _
1, "Folder Name- Select folder and file to open", , False)
If TypeName(fn) = "Boolean" Then Exit Sub
' the user didn't select a file
Debug.Print "Selected file: " & fn
Select Case Right(fn, 3)
Case Is = "xls"
Workbooks.Open fn
Case Is = "doc"
Call GetWord(CStr(fn))
Case Else
MsgBox "How did you select a non xls or doc file?"
End Select
End Sub

Sub GetWord(strFilePath As String)
'Bind to an existing or created instance of Microsoft Word
Dim objApp As Object

'Attempt to bind to an open instance
On Error Resume Next
Set objApp = GetObject(, "Word.Application")

If Err.Number <> 0 Then
'Could not get instance, so create a new one
Err.Clear
On Error GoTo ErrHandler
Set objApp = CreateObject("Word.Application")
With objApp
.Visible = True
End With
Else
'Bound to instance, activate error handling
On Error GoTo ErrHandler
End If

'Open the file
objApp.Documents.Open strFilePath

ErrHandler:
'Release the object and resume normal error handling
Set objApp = Nothing
On Error GoTo 0
End Sub
 
You may try something like this:
ActiveWorkbook.FollowHyperlink Address:=fn

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Do you mean like this???

Sub OpenTechnical_Info()
Dim fn As Variant

ChDir "C:\Program Files\Hannabery\Technical Info"
fn = Application.GetOpenFilename("All files,*.*,Excel-files,*.xls,Word Files,*.doc,PDF Files,*.pdf,", _
1, "Technician Technical Information - Select folder and file to open", , False)
If TypeName(fn) = "Boolean" Then Exit Sub
' the user didn't select a file
Debug.Print "Selected file: " & fn
Select Case Right(fn, 3)

Case Is = "pdf"
ActiveWorkbook.FollowHyperlink Address:=fn

Case Is = "xls"
Workbooks.Open fn
Case Is = "doc"
Call GetWord(CStr(fn))
Case Else
MsgBox "How did you select a non xls or doc file?"
End Select
End Sub
 
That didn't work, I'm sure I did something wrong, any ideas?
 
Still can't open pdf files with this procedure. I'm stumped!
 
And when a PDF came up, what did this line spill out..

Code:
Debug.Print "Selected file: " & fn

??

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Actually, I didn't get any error messages. It almost seemed like the pdf tried to open and then just stops. The screen flashes and then nothing happens.
 
Sorry it took me a while to get back to you here, been very busy and starting to play catchup now. My apologies.

If you are still experiencing difficulties with this, what exactly did that line spill out?

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Hey, thanks for getting back to me. Wow, guess what? I had given up on that, and I just tried it to see what would happen and it worked fine. But it didn't before. I recently upgraded my Adobe Acrobat Reader to the latest version, I wonder if that had something to do with it.

Anyway, thanks for checking back, I appreciate it!
 
Maybe you can help with something else I'm curious about...

Is it possible to replace the Small Excel Icon in the top left corner of the application along with "Microsoft Excel" and the file name, and replace with a custom icon and title?
I also want to disable the upper right X button so the application can only be closed from a custom close button I created.

Thanks,

Puds
 
Pudsters said:
I recently upgraded my Adobe Acrobat Reader to the latest version, I wonder if that had something to do with it.

Yes, there is a bug in Acrobat 7, fixed in version 7.0.8, which causes this problem.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top