I found a macro and made some tweaks to get it to export my workbook, but the issue I am having is that I often have multiple similar workbooks open that I want to export. However when I run this macro, it will not always export the workbook I have selected but some other random one that is open in the background.
How can I make this code run on the specific workbook I am working in?
Thank you.
How can I make this code run on the specific workbook I am working in?
VBA Code:
Sub export_PDF()
Dim NameOfWorkbook
With ActiveWorkbook
ThisWorkbook.Activate
NameOfWorkbook = Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".", -1, vbTextCompare) - 1)) 'removes ".xlsm" from file name
ThisWorkbook.Sheets(Array("Page 1", "Page 2")).Select
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "\" & NameOfWorkbook, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
ActiveWorkbook.Close SaveChanges:=False
End With
End Sub
Thank you.