Change Excel Printer in VB.NET
Posted on 2004-11-10
I have an app that sends info to Excel, then creates a .prn file using the Acrobat Distiller. It works fine when the printer name is hardcoded. But now, I'm to a point where I need to adjust it to work on different PCs and that is a problem. For a reason I don't understand, I've had to assign the name of the Distiller printer with a strange extension to get it to work.
Basically, this is what I need to get working (Windows XP machine):
objExcel.ActivePrinter = "Acrobat Distiller" '<-- Causes an Error
objExcel.ActivePrinter = "Acrobat Distiller on Ne08:" '<--OK
What's the deal with that little "on Ne08:" extension? Is that the port? The code below returns "Acrobat Distiller"
Dim strPrintersList As String
' Find all printers installed, assign Acrobat Distiller
For Each strPrintersList In System.Drawing.Printing.PrinterSettings.InstalledPrinters
If InStr(strPrintersList, "Acrobat Distiller") Then
objExcel.activeprinter = strPrintersList ' <- ERROR HERE
objExcel.ActivePrinter = strPrintersList 'Assign Distiller as printer
I need someone to come through on this one! Sorry, but I can't use a PrintDialog.