Dear All,
I hope that you will be able to help. I have a macro that works perfectly but I need to change/modify it so it will be possible to save all indicated in range tabs as all separated PDFs with name of the tabs as name of the PDFs in the same folder where is the excel file with macro.
VBA to save all the indicated tabs in range A2:A5 as 4 separated PDFs with file name as the tab name e.g., EXCEL TAB 1AAA - save as 1AAA.pdf in the same folder where the main macro file is. In this case macro will create 4 PDFs at once in the main file location. 1AAA.pdf, 3CCC.pdf, 4DDD.pdf, 6FFF.pdf Thank you for your help.
Below macro that save all the TABS from Range A2:A5 as one PDF file not 4 separated files like I want to.
Option Explicit
Sub Save_All_tabs_As_PDF()
Dim PDFfile As String
Dim currentSheet As Worksheet
Dim replaceFlag As Boolean
Dim cell As Range
PDFfile = ThisWorkbook.Path & "\1AAA.pdf"
Set currentSheet = ActiveSheet
With ActiveSheet
replaceFlag = True
For Each cell In .Range("A2:A5")
If cell.Value <> vbNullString Then
Worksheets(cell.Value).Select replaceFlag
replaceFlag = False
End If
Next
If Not replaceFlag Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
currentSheet.Select
MsgBox "PDF created"
Else
MsgBox "No Tabs to save at the moment"
End If
End With
End Sub
I hope that you will be able to help. I have a macro that works perfectly but I need to change/modify it so it will be possible to save all indicated in range tabs as all separated PDFs with name of the tabs as name of the PDFs in the same folder where is the excel file with macro.
VBA to save all the indicated tabs in range A2:A5 as 4 separated PDFs with file name as the tab name e.g., EXCEL TAB 1AAA - save as 1AAA.pdf in the same folder where the main macro file is. In this case macro will create 4 PDFs at once in the main file location. 1AAA.pdf, 3CCC.pdf, 4DDD.pdf, 6FFF.pdf Thank you for your help.
Below macro that save all the TABS from Range A2:A5 as one PDF file not 4 separated files like I want to.
Option Explicit
Sub Save_All_tabs_As_PDF()
Dim PDFfile As String
Dim currentSheet As Worksheet
Dim replaceFlag As Boolean
Dim cell As Range
PDFfile = ThisWorkbook.Path & "\1AAA.pdf"
Set currentSheet = ActiveSheet
With ActiveSheet
replaceFlag = True
For Each cell In .Range("A2:A5")
If cell.Value <> vbNullString Then
Worksheets(cell.Value).Select replaceFlag
replaceFlag = False
End If
Next
If Not replaceFlag Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
currentSheet.Select
MsgBox "PDF created"
Else
MsgBox "No Tabs to save at the moment"
End If
End With
End Sub