Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub SwitchPrinter()
- Dim prt As Printer
- ' Get current default printer
- Set prt = Application.Printer
- ' Set default printer
- Application.Printer = Application.Printers("OtherPrinter")
- ' Print something, e.g.
- DoCmd.PrintOut
- ' Restore original printer
- Set Application.Printer = prt
- End Sub
- Sub ListPrinters()
- Dim prt As Printer
- For Each prt In Printers
- Debug.Print prt.DeviceName
- Next prt
- End Sub
- //http://www.exceltip.com/printing-in-vba/change-the-default-printer-using-vba-in-microsoft-excel.html
- Option Explicit
- Sub PrintToAnotherPrinter()
- Dim STDprinter As String
- STDprinter = Application.ActivePrinter
- Application.ActivePrinter = “Microsoft fax on fax:”
- Activesheet.Printout
- Application.ActivePrinter = STDprinter
- End Sub
- Sub printersetup()
- curPrinter = Application.ActivePrinter
- Application.ActivePrinter = "Microsoft XPS Document Writer on Ne01:"
- ''Print documents
- Application.ActivePrinter = curPrinter
- End Sub
- Sub FindPrinter()
- Dim strPName As String
- strPName = Application.ActivePrinter
- '******Finds the current printer name ********
- Application.ActivePrinter = "Nitro PDF Creator 2 on Ne08:"
- ***** Does your print job *******
- Application.ActivePrinter=strPName
- **** Then resets the printer to it's default*****
- End Sub
- ''https://www.mrexcel.com/forum/excel-questions/631263-set-default-printer.html
- Function GetPrinterWithPort(ByVal PrinterName As String) As String
- Dim Port As Variant
- Dim WSH As Object
- Set WSH = CreateObject("WScript.Shell")
- On Error Resume Next
- Port = WSH.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts\" & PrinterName)
- If Err = 0 Then
- Port = Split(Port, ",")(1)
- GetPrinterWithPort = PrinterName & " on " & Port
- End If
- On Error GoTo 0
- End Function
- Sub PrintPersonalPdf()
- Dim strPName As String
- strPName = Application.ActivePrinter
- Application.ActivePrinter = GetPrinterWithPort("Nitro PDF Creator 2")
- Application.Run "PrintPersonalFax"
- Application.ActivePrinter = strPName
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement