jtrombley24
New Member
- Joined
- Feb 21, 2016
- Messages
- 27
Guys - the following code is causing an infinite loop because when the ExportAsFixedFormat runs, the code goes back to the top of the procedure.
How can I save as a pdf and still run the BeforePrint event?
(By the way, I've tried including the pdf code in the BeforePrint subroutine and also tried passing parameters to a module. No luck either way)
Thanks in advance!
How can I save as a pdf and still run the BeforePrint event?
(By the way, I've tried including the pdf code in the BeforePrint subroutine and also tried passing parameters to a module. No luck either way)
Thanks in advance!
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
'MsgBox "Do not use this method for printing." & vbNewLine & vbNewLine & "Click on the print button located on the NOID report page.", vbExclamation + vbOKOnly, "Print Error"
Dim i As Integer
Dim lotNum As String
Dim sfilename As String
lotNum = NOIDsheet.Cells(20, 1).Value
' loop through lot numbers to build file name
For i = 21 To 33
If NOIDsheet.Cells(i, 1).Value <> "" Then
lotNum = lotNum & " " & NOIDsheet.Cells(i, 1).Value
End If
Next i
' add a - to the end so that the username/date can be appended
lotNum = Trim(lotNum) & "-"
' append the username/date to the file name
sfilename = lotNum & Trim(NOIDsheet.Range("C5").Value)
' filepath to the sharepoint site
Dim shptfilepath As String
shptfilepath = DataSheet.Range("B2").Value
NOIDsheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=shptfilepath & "\" & sfilename, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub