VBA code to open pdf document

yoni24

New Member
Joined
Jun 28, 2011
Messages
1
Hello,

This is my first post so please be patient....

I have created a macro that saves a worksheet as pdf, lets the user select location for saving the file, lets the user choose whether to open the file and folder where its located.

My issue is that i cant work out how to get the macro to open the resulting pdf file. i get an error "cannot open specified file"

Everything else works fine...

I have used a lot of help from this forum...

Please help...

excel 2010, windows 7

Code:
Sub Make_PDF()
' Create and save .pdf
'*****USE THIS VERSION OF THE MACRO******'
Dim myval As Variant, strPath As String, pdfName As String, FullName As String, username As String, strDirname As String, strPathname As String, strDefpath As String
On Error GoTo Errorcatch
pdfName = Range("A1").Text
username = Range("A3").Text
FullName = strPath & "\" & pdfName & ".pdf"
Call BrowseForFolder(dhcCSIdlDesktop, dhcBifReturnOnlyFileSystemDirs, _
strPath, pszTitle:="Select a folder:")
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfName _
, Quality:=xlQualityMedium, IncludeDocProperties:=False, _
IgnorePrintAreas:=False
YesNo = MsgBox("Would you like to see the report now?", vbYesNo + vbQuestion, "Open Report?")
Select Case YesNo
Case vbYes
ThisWorkbook.FollowHyperlink pdfName & ".pdf"
 Case vbNo
End Select
YesNo = MsgBox("Would you like to open the folder where the report was saved?" _
, vbYesNo + vbQuestion, "Open Folder?")
Select Case YesNo
Case vbYes
ActiveWorkbook.FollowHyperlink Address:=strPath, NewWindow:=False
Case vbNo
End Select
Exit Sub
Errorcatch:
MsgBox Err.Description
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You need to supply the full path & file name eg.
Code:
f = "F:\test.pdf"
ActiveWorkbook.FollowHyperlink f
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top