spongebob
Board Regular
- Joined
- Oct 25, 2004
- Messages
- 68
- Office Version
- 2019
- Platform
- Windows
Hello All,
I had something written a while back ago and its been overall pretty flawless, but recently it's decided to not work.
the part in particular is related to printing the tabs within the current document.
We have a list in a column of excluded tabs, and the script goes out and makes PDF's for the rest of the tabs, then physically prints the first page of each document.
Unfortunately with no error trapping, I don't get much value to help diagnose the issue.
After saving the first PDF printing it, it then crashes with a run-time error '1004':
if I click debug, I get the following:
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=tempstring, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
I have attached the 2 functions that save the PDF and Print, any assistance appreciated...
I had something written a while back ago and its been overall pretty flawless, but recently it's decided to not work.
the part in particular is related to printing the tabs within the current document.
We have a list in a column of excluded tabs, and the script goes out and makes PDF's for the rest of the tabs, then physically prints the first page of each document.
Unfortunately with no error trapping, I don't get much value to help diagnose the issue.
After saving the first PDF printing it, it then crashes with a run-time error '1004':
if I click debug, I get the following:
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=tempstring, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
I have attached the 2 functions that save the PDF and Print, any assistance appreciated...
VBA Code:
Private Sub InvoicePdf(ws As Worksheet, CoName As String, SerPeriod As String)
Dim tempstring As String
If Right(ThisWorkbook.Sheets("Mapping_DB").Range("fname").Value, 1) = "\" Then
tempstring = ThisWorkbook.Sheets("Mapping_DB").Range("fname").Value & CoName & "-" & Replace(SerPeriod, "/", "-") & ".PDF"
Else
tempstring = ThisWorkbook.Sheets("Mapping_DB").Range("fname").Value & "\" & CoName & "-" & Replace(SerPeriod, "/", "-") & ".PDF"
End If
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=tempstring, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
ws.PrintOut From:=1, To:=1, Copies:=1, Preview:=False
End Sub
Sub PrintAllSheets()
Dim mySht As Worksheet
Dim timestartp As String
timestartp = Application.WorksheetFunction.Text(Now(), "hh:mm:ss")
For Each mySht In ThisWorkbook.Worksheets
With mySht
If IsError(Application.Match(.Name, Sheets("Mapping_DB").Range("ExclTabs").Value, 0)) Then
Call InvoicePdf(mySht, mySht.Range("B5").Value, mySht.Range("D2").Value)
End If
End With
Next mySht
MsgBox "Done, started at " & timestartp & vbCrLf & "Completed at " & Application.WorksheetFunction.Text(Now(), "hh:mm:ss")
End Sub