Small Paul
Board Regular
- Joined
- Jun 28, 2018
- Messages
- 118
Hi
I have searched various websites/forums and tried the solutions but without success. I am hoping somebody here can help on this issue.
The code below basically has 3 stages:
1) Create a new folder and save the master file (this works properly)
2) Save the active sheet as a pdf (this does not work AT ALL)
3) Select next worksheet (this works properly)
I need:
- each worksheet (from 3 to 'variable') to be saved as an individual PDF
- in the newly created folder - Z:\Paul\Commission Paid\[today's date]
- with a file name using the contents of cell B4 on each worksheet
Any and all assistance appreciated.
Cheers
Small Paul.
I have searched various websites/forums and tried the solutions but without success. I am hoping somebody here can help on this issue.
The code below basically has 3 stages:
1) Create a new folder and save the master file (this works properly)
2) Save the active sheet as a pdf (this does not work AT ALL)
3) Select next worksheet (this works properly)
Code:
Sub Comms_Statements_Save_As_PDFs()'
' Save_As_PDFs Macro
Dim Path As String
Dim d As String
Dim sh As Worksheet
Dim WS_Count As Integer
Dim strFolder As String
Dim strFile As String
Dim I As Integer
d = Format(Date, "yyyy-mm-dd")
'create folder
strFolder = "Z:\Paul\Commission Paid\"
strFile = activesheet.range("B4").value
strFolder2 = "Z:\Paul\Commission Paid\" & d
Path = "Z:\Paul\Commission Paid\"
If Len(Dir(Path, vbDirectory)) = 0 Then
MsgBox "Path does not exist.", vbCritical
Exit Sub
End If
If Len(Dir(Path & d, vbDirectory)) = 0 Then MkDir (Path & d)
ActiveWorkbook.SaveAs Filename:=strFolder & d & "\" & " " & "Commission Statements" & ".xlsm"
Sheets("1").Activate
'Convert Each Sheet to PDF and Save
WS_Count = ActiveWorkbook.Worksheets.Count
For I = 3 To Sheets.Count
range("B4").Select
activesheet.ExportAsFixedFormat Type:=xlTypePDF
Filename = strFolder2 & "\" & strFile & ".pdf"
quality = xlQualityStandard
includedocproperties = True
ignoreprintareas = False
openafterpublish = False
I = I + 1
activesheet.Next.Select
Next
End Sub
I need:
- each worksheet (from 3 to 'variable') to be saved as an individual PDF
- in the newly created folder - Z:\Paul\Commission Paid\[today's date]
- with a file name using the contents of cell B4 on each worksheet
Any and all assistance appreciated.
Cheers
Small Paul.