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
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