zhengzhi8806
New Member
- Joined
- Apr 16, 2018
- Messages
- 2
Hi
I am trying to write a macro to save selected worksheets from the workbook to individual pdfs. but I only got the macro to work to print all the worksheets from the workbook including summary tab and notes tab. I only want to print the tabs that are employee statements. Each individual tab is named as employee name. How can i get the code to work only print the employee statements.
I am trying to write a macro to save selected worksheets from the workbook to individual pdfs. but I only got the macro to work to print all the worksheets from the workbook including summary tab and notes tab. I only want to print the tabs that are employee statements. Each individual tab is named as employee name. How can i get the code to work only print the employee statements.
Code:
Option Explicit
Sub WorksheetLoop()
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
Dim WS_Count As Integer
' Set WS_Count equal to the number of worksheets in the active workbook.
Set wbA = ActiveWorkbook
WS_Count = wbA.Worksheets.Count
strPath = wbA.Path
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & ""
' Begin the loop.
For Each wsA In wbA.Worksheets
wsA.Activate
'replace spaces and periods in sheet name
strName = Replace(wsA.Name, " ", "")
strName = Replace(strName, ".", "_")
'create default name for savng file
strFile = strName & ".pdf"
myFile = strPath & strFile
Debug.Print myFile
'export to PDF if a folder was selected
If myFile <> "False" Then
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next wsA
End sub
Last edited by a moderator: