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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

view PDF from Excel macro 2

Status
Not open for further replies.

PapaSmurf

IS-IT--Management
May 16, 2001
48
GB
I currently havea hotkey set up i an excel document, the contents of which is:

Dim retval
retval = Shell("c:\program files\adobe\acrobat 4.0\reader\acrord32 \\server\orders\" + ActiveSheet.Range(ActiveWindow.RangeSelection.Address) + ".pdf", vbNormalFocus)

This works fine if the user has Acrobat 4.0 installed into the default folder, but i want to open a PDF without having to specify the adobe exe.

Is this possible?
 
Yes indeed ! you need the wonderful SHELLexecute command.

Just dump this into a SEPARATE module and run it from your program, passing the full file name as a parameter.

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

Declare Function apiFindWindow Lib "User32" Alias "FindWindowA" _
(ByVal lpclassname As Any, ByVal lpCaption As Any) As Long

Global Const SW_SHOWNORMAL = 1

Sub ShellExecuteFileOpen(NewFN)
Dim hwnd
Dim StartDoc
hwnd = apiFindWindow("OPUSAPP", "0")

StartDoc = ShellExecute(hwnd, "open", NewFN, "", _
"C:\", SW_SHOWNORMAL)
End Sub

Richard
 
Richard,

Many thanks kind sir, perfect answer! I thought my question would never be answered, so thanks again!

Ben
 
Excellent! That works like a charm! I was looking for EXACTLY that! :))

Leanne
 
I have also found this function very useful, so many thanks tbl.

The icing on the cake would be to be able to open the pdf document at a specific page or paragraph... is this possible? [I've looked in the Abobe Acrobat Forum, with little success]

Many thanks

Andy.
 
Alternatively, let your browser do the work with ...
Code:
  ActiveWorkbook.FollowHyperlink _
    Address:="filename.pdf", _
    NewWindow:=True
  Exit Sub
Also easy to start the email client, if you ever need to do that ...
Code:
ActiveWorkbook.FollowHyperlink _
  Address:="mailto:YourName@YourServer.com" & _
           "?Subject=Test 1 2 3" & _
           "&Body=Line%20One%0D" & _
                 "Line%20Two%0D" & _
                 "Line%20Three", _
  NewWindow:=True
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top