BrendanDixon
Board Regular
- Joined
- Mar 7, 2010
- Messages
- 174
- Office Version
- 365
- 2019
- Platform
- Windows
Hi All,
I have been trying to create a macro where I can print my Workbook as an XPS file using the XPS document Writer Driver.
This is my code so far:
The problems I am having is that it is also printing to my default printer on my computer. I noticed that without the STDprinter code the quickprint button from the menu would default to the XPS printer where I would like the default printer to change back to my computers default printer afterwards, and not print it on the default printer as well.
I would also like to set the filename automatically in the XPS document Does anyone know how I can do this ?
Thanks
I have been trying to create a macro where I can print my Workbook as an XPS file using the XPS document Writer Driver.
This is my code so far:
Code:
Sub PRINT_UNKNOWN_Ne()
Dim PrinterName As String
Dim PortNumber As Integer
Dim PrinterPort As String
Dim PrinterFullName As String
Dim PrinterFound As Boolean
Dim STDprinter As String
STDprinter = Application.ActivePrinter
PrinterName = "Microsoft XPS Document Writer"
PrinterFound = False
On Error Resume Next
For PortNumber = 0 To 12
PrinterPort = "Ne" & Format(PortNumber, "00") & ":"
PrinterFullName = PrinterName & PrinterNumber & " on " & PrinterPort
Application.ActivePrinter = PrinterFullName
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
If Err.Number = 0 Then
PrinterFound = True
Exit For
Else
Err.Clear
End If
Next PortNumber
If PrinterFound = False Then
MsgBox (PrinterName & vbCr & "Printer not found")
End If
Application.ActivePrinter = STDprinter
End Sub
I would also like to set the filename automatically in the XPS document Does anyone know how I can do this ?
Thanks