Hello All,
A rather unusual question for y'all. I have two set's of code that work perfectly fine individually but I am not sure how to combine them.
First bit of code, loops through the network printers and select's CutePDF as the default printer.
Function fnSetCutePDFPrinter() As Boolean
Dim strNE As String, blnWrongNe As Boolean, i As Integer
On Error GoTo err_fnSetCutePDFPrinter
Application.ActivePrinter = "CutePDF Writer on CPW:"
If blnWrongNe = -1 Then
blnWrongNe = 0
For i = 1 To 99
If i < 10 Then
strNE = "CPW"
Else
strNE = "CPW"
End If
Application.ActivePrinter = "CutePDF Writer on " & strNE & i & ":"
If Not blnWrongNe Then
fnSetCutePDFPrinter = -1
Exit Function
End If
blnWrongNe = 0
Next i
End If
err_fnSetCutePDFPrinter:
blnWrongNe = -1
Err.Clear
Resume Next
End Function
Second does the actual printing (creating PDF's)
Sub PrintAsPDF2()
If Range("B49") = "" Then
Debug.Print
ActiveSheet.PageSetup.PrintArea = "$A$1:$AN$48,$A$529:$AN$550"
ActiveSheet.PrintOut From:=1, To:=21, Copies:=1, ActivePrinter:="CutePDF Writer on CPW2", Collate:=True, IgnorePrintAreas:=False
Else
ActiveSheet.PageSetup.PrintArea = "$A$1:$AN$550"
ActiveSheet.PrintOut From:=1, To:=22, Copies:=1, ActivePrinter:="Adobe PDF", Collate:=True, IgnorePrintAreas:=False
End If
End Function
When I added the first one ahead of the second one, I get an Compile Error: Expected End Sub. what am I doing wrong and what changes should I make so the it runs as expected?
loops thru and find the CutePDF printer
execute the print command?
Sub PrintAsPDF2()
Function fnSetCutePDFPrinter() As Boolean
Dim strNE As String, blnWrongNe As Boolean, i As Integer
On Error GoTo err_fnSetCutePDFPrinter
Application.ActivePrinter = "CutePDF Writer on CPW:"
If blnWrongNe = -1 Then
blnWrongNe = 0
For i = 1 To 99
If i < 10 Then
strNE = "CPW"
Else
strNE = "CPW"
End If
Application.ActivePrinter = "CutePDF Writer on " & strNE & i & ":"
If Not blnWrongNe Then
fnSetCutePDFPrinter = -1
Exit Function
End If
blnWrongNe = 0
Next i
End If
err_fnSetCutePDFPrinter:
blnWrongNe = -1
Err.Clear
Resume Next
End Function
If Range("B49") = "" Then
Debug.Print
ActiveSheet.PageSetup.PrintArea = "$A$1:$AN$48,$A$529:$AN$550"
ActiveSheet.PrintOut From:=1, To:=21, Copies:=1, ActivePrinter:="CutePDF Writer on CPW2", Collate:=True, IgnorePrintAreas:=False
Else
ActiveSheet.PageSetup.PrintArea = "$A$1:$AN$550"
ActiveSheet.PrintOut From:=1, To:=22, Copies:=1, ActivePrinter:="Adobe PDF", Collate:=True, IgnorePrintAreas:=False
End If
End Function
Thanks,
Aadesh Gandhi
Bookmarks