Open PDF located in excel with macro
Ken
Add the code to the Worksheet, right click on worksheet and select "View
code". Then in the left side menu bar select "General", paste this code in
that area:
'======
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
'This is the function that does the work
Public Sub OpenAcrobatFile(strFile As String)
ShellExecute 0, "open", strFile, vbNullString, vbNullString, 9
End Sub
'======
Paste this sub below that point in the same worksheet.
'======
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sS
On Error Resume Next
sS = ActiveCell.Name.Name
On Error GoTo 0
If sS = "_hyp1" Then
OpenAcrobatFile "C:\My Documents\SomeFile.pdf" "your path\file here
sS = ""
Else
sS = ""
End If
End Sub
'======
Go to your worksheet and name the Cell you want to trigger the event to
something memorable, in this case I used "_hyp1" (hyperlink 1).
To name a cell, select the cell you desire, in the upper left hand corner
just above column A is a box that shows the cell address you selected. Click
in that box and it will auotmatically highlite the text. Type a name for the
cell (can't be the cell address). Press "Enter" key. Now when you select
that cell it should open the PDF file in your code from within excel.
Now no matter how many cells, rows or columns you add or subtract, the cell
will always be active with out having to change the address unless you delete
the named cell. Then you simply apply the name to another cell.
HTH
--
Regards
VBA.Noob.Confused
XP Pro
Office 2007
"Ken" wrote:
Thank you for your help Rick. But I would like to have the pdf file with the
user guide located within the excel file, and then have it to open when I
click the "User guide" button on my commandbar. The reason is that the excel
model is supposed to be distributed to many other users, and they will not
have access to my drive.
Do you (or anyone else) know have this can be done?
Thanks
"Rick S." skrev:
Found the author: Jean-Guy Marcil
;)
--
Regards
VBA.Noob.Confused
XP Pro
Office 2007
"Rick S." wrote:
I got this code from this NG, unfortunately I did not save the authors name.
'======
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
'This is the function that does the work
Public Sub OpenAcrobatFile(strFile As String)
ShellExecute 0, "open", strFile, vbNullString, vbNullString, 9
End Sub
Sub test() 'command line parameters
OpenAcrobatFile "C:\My Documents\Somefile.PDF" 'your "drive:\path\file name"
here
End Sub
'======
HTH
--
Regards
VBA.Noob.Confused
XP Pro
Office 2007
"Ken" wrote:
I have an excel model which I have made a user guide for. This userguide is a
pdf file. In my excel model I have created a commandbar with a button saying
"User guide". When I click this button I would like the User guide to open.
I have 2 questions:
1) How do I save my user guide in pdf format within the excel model, so it
can be accessed from any computer.
2) How do I get the user guide to open when I click the "User guide button"
on my commandbar.
Thanks
|