Hi All,
I have a script that prints an entire workbook to PDF, but it seems to give problems if the file is not saved before the script is run. Script is here:
I can't figure out where the code is going wrong to produce the error. It seems not to happen after the file is saved to .xlsm format, though, so I thought I could automatically save the file before running the code. I'm not sure how to do that, though.
...any ideas?
I have a script that prints an entire workbook to PDF, but it seems to give problems if the file is not saved before the script is run. Script is here:
Code:
Sub PrintPDF()
Dim fp As String, fn As String, model As String
Dim wb As Workbook
Sheets("Release").Visible = False
Calc_Footer
fn = Sheets("General Data").Range("C10").Value
alt_fn = "SCP " & Sheets("General Data").Range("B10").Value
fp = ThisWorkbook.Path & "\" & fn
If fn = "" Then
Dim ansfn
ansfn = MsgBox("Report Number missing. Press OK to complete form else Cancel to print blank form", vbOKCancel, "Report Incomplete!")
If ansfn = vbOK Then
Exit Sub
Else:
fp = ThisWorkbook.Path & "\" & alt_fn
End If
End If
Dim ans
ans = MsgBox("Output file will be saved in the same directory as the original file", vbOKCancel)
If ans = vbCancel Then
Exit Sub
End If
Sheets("Summary").Unprotect Password:="Z8_Service"
Sheets("Summary").Range("B57") = "Report Finalized on " & Format(Date, "dd-mmm-yyyy") & " By:"
Set wb = ActiveWorkbook
wb.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=fp, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Sheets("Summary").Range("B57") = "Print and sign or place digital signature here after finalizing form."
Sheets("Summary").Protect Password:="Z8_Service"
Sheets("Release").Visible = True
End Sub
I can't figure out where the code is going wrong to produce the error. It seems not to happen after the file is saved to .xlsm format, though, so I thought I could automatically save the file before running the code. I'm not sure how to do that, though.
...any ideas?