sydneylacey
New Member
- Joined
- Feb 13, 2018
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
I'm in the process of expanding my VBA knowledge/skills and I've hit a snag in my current little self-assigned learning project. I have a simple dynamic calendar sheet that I'd like for end-users to be able to save as PDF to a location they select with the name pre-loaded based on the contents of a particular cell. The worksheet will have two buttons (one to clear the contents and reset the calendar and one to active the dialogue box to save the pdf).
I thought I was on the right track. Running the code opens the save as dialogue box and it has the correct file name but actually hitting the Save button gives me the Run-time error "1004" message.
I'm sure it's an easy fix for someone with more skill than this newbie has under her belt.
Here's my code:
I thought I was on the right track. Running the code opens the save as dialogue box and it has the correct file name but actually hitting the Save button gives me the Run-time error "1004" message.
I'm sure it's an easy fix for someone with more skill than this newbie has under her belt.
Here's my code:
VBA Code:
Private Sub clear_btn_Click()
Call ClearContents
End Sub
Private Sub SavePDF_btn_Click()
Call Save_Excel_As_PDF
End Sub
Sub Save_Excel_As_PDF()
Dim PDFFilename As Variant
PDFFilename = Application.GetSaveAsFilename( _
InitialFileName:=ActiveSheet.Range("B3").Value, _
FileFilter:="PDF, *.pdf", _
Title:="Save As PDF")
With ActiveSheet.PageSetup
.Orientation = x1Landscape
.PrintArea = "$B$3:$H$14"
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
End With
ActiveSheet.ExportAsFixedFormat _
Type:=x1TypePDF, _
Filename:=ActiveSheet.Range("B3").Value, _
Quality:=x1QualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=1, _
OpenAfterPubllish:=True
End Sub