Hi all,
I looked up a macro on this site to print an excel sheet to pdf, but I'm running into some issues when using it. Now, the post is 8 years old, so I suspect some of the commands have changed since it was posted. The error that I'm getting is a compile error "Assignment to constant not permitted" on the "vbYesNo" on the last messagebox line.
Thanks for your help!
Sub Make_PDF()
' Create and save .pdf
Dim pdfName As String, FolderName As String, FullName As String
' change to cell with file name that you want
pdfName = Range("h3").Text
' change to cell with folder name that you want
FolderName = Range("H4").Text
'change directory to where you want it saved
If Not DirExists("C:\Users\mittar.khalsa\Desktop\test" & FolderName) Then MkDir "C:\Users\mittar.khalsa\Desktop\test" & FolderName
'change directory to where you want it saved
FullName = "C:\Users\mittar.khalsa\Desktop\test" & FolderName & "" & pdfName & ".pdf"
If MsgBox("Please confirm that name and location is correct: " & FullName & ". - " & " Is it correct?", vbYesNo + vbQuestion, "Confirm File Name and Location") = vbNo Then Exit Sub
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FullName _
, Quality:=xlQualityStandard, IncludeDocProperties:=False, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
vbYesNo = MsgBox("Would you like to open the folder where the invoice was saved?" _
, vbYesNo + vbQuestion, "Open Folder?")
Select Case YesNo
Case vbYes
'change directory to where you want it saved
myval = Shell("explorer C:\Users\mittar.khalsa\Desktop\test" & FolderName, 1)
Case vbNo
End Select
End Sub
I looked up a macro on this site to print an excel sheet to pdf, but I'm running into some issues when using it. Now, the post is 8 years old, so I suspect some of the commands have changed since it was posted. The error that I'm getting is a compile error "Assignment to constant not permitted" on the "vbYesNo" on the last messagebox line.
Thanks for your help!
Sub Make_PDF()
' Create and save .pdf
Dim pdfName As String, FolderName As String, FullName As String
' change to cell with file name that you want
pdfName = Range("h3").Text
' change to cell with folder name that you want
FolderName = Range("H4").Text
'change directory to where you want it saved
If Not DirExists("C:\Users\mittar.khalsa\Desktop\test" & FolderName) Then MkDir "C:\Users\mittar.khalsa\Desktop\test" & FolderName
'change directory to where you want it saved
FullName = "C:\Users\mittar.khalsa\Desktop\test" & FolderName & "" & pdfName & ".pdf"
If MsgBox("Please confirm that name and location is correct: " & FullName & ". - " & " Is it correct?", vbYesNo + vbQuestion, "Confirm File Name and Location") = vbNo Then Exit Sub
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FullName _
, Quality:=xlQualityStandard, IncludeDocProperties:=False, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
vbYesNo = MsgBox("Would you like to open the folder where the invoice was saved?" _
, vbYesNo + vbQuestion, "Open Folder?")
Select Case YesNo
Case vbYes
'change directory to where you want it saved
myval = Shell("explorer C:\Users\mittar.khalsa\Desktop\test" & FolderName, 1)
Case vbNo
End Select
End Sub