I have a macro that prints a single worksheet to a pdf file, which I've used successfully many times. I moved this code into a new workbook, and it doesn't work. When I get to the ActiveSheet.ExportAsFixedFormat portion of the code, I get a Run-time error '5': Invalid procedure call or argument error.
What can I do to make this code work in my new workbook?
VBA Code:
Sub Print_pdf
Dim xWB As Workbook
Dim xFSO As Object
Dim xFileName As String
Set xWB = ActiveWorkbook
Set xFSO = CreateObject("Scripting.FileSystemObject")
xFileName = xWB.Path & "\" & xFSO.GetBaseName(xWB.Name) & ".pdf"
xWB.Sheets("Sheet1").Select
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=xFileName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
What can I do to make this code work in my new workbook?