[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Change Excel Printer in VB.NET

Posted on 2004-11-10
11
Medium Priority
?
1,702 Views
Last Modified: 2009-12-16
Hi Experts,
  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
                End If
            Next strPrintersList

            objExcel.ActivePrinter = strPrintersList   'Assign Distiller as printer

I need someone to come through on this one!  Sorry, but I can't use a PrintDialog.
Thanks experts!
-Ren
0
Comment
Question by:Ren
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 12552278
Ne08 semes to be the machine name
0
 

Author Comment

by:Ren
ID: 12554415
So, how do I incorporate Ne08 into the printer name so that I will be able to assign my Acrobat Distiller as excel's active printer?

-Ren
0
 
LVL 2

Expert Comment

by:dsabo
ID: 12562163
You should look at the shared printer properties, and change the rename the printer. that would work.

look at your Printers, and change the name of the printer
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Ren
ID: 12567226
Thanks for the advice, dsabo.  I looked at the properties and it says the name of the printer is "Acrobat Distiller".  Does that make sense??  That's what is so weird, this line:

For Each strPrintersList In System.Drawing.Printing.PrinterSettings.InstalledPrinters

... gets the name of the printer I want and sets strPrintersList = "Acrobat Distiller".  That is exactly what I want.  But the assignment of objExcel.ActivePrinter = strPrintersList is where the problem occurs.

Before, I was just using this statement to hardcode the printer:
objExcel.ActivePrinter = "Acrobat Distiller on Ne08:"

...and that worked fine.

This causes an error because strPrintersList  = "Acrobat Distiller" without the "on Ne08:" statement:
objExcel.activeprinter = strPrintersList   ' <- ERROR HERE

So, if the name of the printer is "Acrobat Distiller" then what is the "on Ne08" and why can't I assign the printer.  What am I not seeing?

Just a side note, I do a similar thing with Word and strPrintersList = "Acrobat Distiller" DOES work with word.  This seems to be specific to Excel.

Thanks!
-Ren
0
 
LVL 2

Expert Comment

by:dsabo
ID: 12568193
Try to rename the printer on the control panel /printers.....

rename the printer name, but not in the properties.
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12572298
I think "on Ne08" will work always when you are printing an Excel file.
So just hardcode it when you are going to print an Excel file
0
 

Author Comment

by:Ren
ID: 12584113
 I wish it were that easy, armoghan, I wondered if it was "Ne08" on all computers too.  But I checked on a co-workers' computer and theirs is "Ne14".  So I can't take a chance like that with an app that the entire office will be using.  I suppose, at worst, I could just cycle through and concatenate "Acrobat Distiller" with every combination of "Ne01" through "Ne99" until I made a successful printer reassignment.  I may end up doing that if nobody can figure this one out.
  dsabo, thanks again for the advice, but the name in the control panel / printer is still just "Acrobat Distiller" without that extension.  This is very confusing.  Really, the only way I've been able to find the name with the extension is to open excel, then the vba screen and type "? Application.activeprinter" in the immediate window.  It's also with any other printer, like my default networked printer also has an extension like that.  I am wondering if it's some kind of Windows XP thing.

-Ren
0
 

Author Comment

by:Ren
ID: 12585556
 I decided to go ahead and just loop through all the possible numbers Ne could have, this solution seems to do the trick.  All I do is loop through 1 to 99 and concatenate that with a "Acrobat Distiller on Ne" string.  If I can set Excel's activeprinter to the concatenated string, I know it worked.

        Do While (1)
            For NeoCTR = 1 To 99
                Try
                    If NeoCTR < 10 Then
                        objExcel.ActivePrinter = "Acrobat Distiller on Ne0" & NeoCTR & ":"
                    Else
                        objExcel.ActivePrinter = "Acrobat Distiller on Ne" & NeoCTR & ":"
                    End If
                    'will only get to this point with a successful assign, otherwise Err
                    Exit Do
                Catch x As Exception
                    If NeoCTR = 99 Then
                        MsgBox("Cannot locate Acrobat Distiller printer. Unable to continue.")
                        g_blnAbortAll = true
                        Exit Sub
                    End If
                End Try
            Next NeoCTR
        Loop

I'll leave this open for awhile to see if anyone can figure out what the "on Ne08" means.
Thanks all!

-Ren
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12681059
Closed, 500 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question