Runtime Error '1004':

outback

New Member
Joined
Aug 3, 2006
Messages
19
How do I fix the following problem? The code runs fine on my computer but when switching to another computer on the same network, mapped to the same printer it won't run through the macro without this error on their computer. However, you can go to file, print, and select this printer and it prints out without any problem to the printer specified in the code.

Runtime Error '1004':

Method 'ActivePrinter' of object '_Application' failed

Code:
    Application.ActivePrinter = "hp color LaserJet 4600 on Ne05:"
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
        "hp color LaserJet 4600 on Ne05:", Collate:=True
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Check to see if the printer is named the same way and works on the same port in control panel > printer.

The fact that the problem occurs on different computers makes this a likely issue.

Don't know if there is VBA to get the default printer on a certain machine though.

EDIT: seems you can use 'application.activeprinter' to get the name of the default printer. Try that.

EDIT2: See here for usable code http://www.erlandsendata.no/english/index.php?d=envbaprintchangeprinter
 
Upvote 0
Application.ActivePrinter = "hp color LaserJet 4600 on Ne05:"

I would presume that hp color LaserJet 4600 isn't on Ne05 in this other person's computer. You can check what all the installed printers are by using this code:

Code:
Sub Printers()
Set WshNetwork = CreateObject("WScript.Network")
Set objPrinters = WshNetwork.EnumPrinterConnections
PrinterStr = "Printers:" & Chr(13)
For i = 0 To objPrinters.Count - 1 Step 2
PrinterStr = PrinterStr & "Printer " & objPrinters.Item(i) & " = " & objPrinters.Item(i + 1) & Chr(13)
Next
MsgBox PrinterStr
End Sub
 
Upvote 0
Application.ActivePrinter = "hp color LaserJet 4600 on Ne05:"

I would presume that hp color LaserJet 4600 isn't on Ne05 in this other person's computer. You can check what all the installed printers are by using this code:

Code:
Sub Printers()
Set WshNetwork = CreateObject("WScript.Network")
Set objPrinters = WshNetwork.EnumPrinterConnections
PrinterStr = "Printers:" & Chr(13)
For i = 0 To objPrinters.Count - 1 Step 2
PrinterStr = PrinterStr & "Printer " & objPrinters.Item(i) & " = " & objPrinters.Item(i + 1) & Chr(13)
Next
MsgBox PrinterStr
End Sub

This returns the exact values on both of our machines, neither of them showing anything about Ne05 though.
Is the Ne05 part of the network infrastructure or what does that refer to?
How can I get that to also show in the name? Any other suggestions as to why it will print on mine and not someone elses machine?
 
Upvote 0
Another twist to my situation.
When running the first macro that prints it throws this error, so I manually print it to the printer that is listed above. I run the 2nd macro that does some other stuff than prints and it prints fine.

Is there anything when these two Macros are started to make it ask me what printer I want to print the specified number of copies to?
 
Upvote 0
Can you post the message that gets generated when my code runs (this needs to be done from both computers as the relative positions of the printers ie row1,row 2, row 3 sets which Ne0x they are on). Instead of a msgbox, do a Debug.Print so you can copy and paste from the Immediate Window.
 
Upvote 0
Mine:

Printers:
Printer IP_10.21.130.120 = RICOH Aficio 2045e PCL 6
Printer Microsoft Document Imaging Writer Port: = Microsoft Office Document Image Writer
Printer USB001 = Lexmark X6100 Series
Printer HPLaserJet8000Series = HP LaserJet 8000 Series
Printer USB004 = hp deskjet 9600 series
Printer hpcolorLaserJet4600 = hp color LaserJet 4600
Printer HPColorLaserJet2840 = HP Color LaserJet 2840
Printer NUL: = Fax Lexmark X6100 Series
Printer USB003 = DYMO LM400
Printer LPT1: = AGFA-AccuSet v52.3

Hers:

Printers:
Printer WebEx Document Sharing Port = WebEx Document Loader
Printer Microsoft Document Imaging Writer Port: = Microsoft Office Document Image Writer
Printer HPLaserJet8000Series = HP LaserJet 8000 Series
Printer USB002 = hp deskjet 9600 series
Printer hpcolorLaserJet4600 = hp color LaserJet 4600
Printer HPColorLaserJet2840_copy_1 = HP Color LaserJet 2840
 
Upvote 0
I figured it out, thanks to everyone here! I was searching the Archives and found my answer. Below is how I done it for future reference.
I inserted the below code at the top of my macro that does everything else, so basically I created a macro, which is called by the main macro. I'll start to incorporate code once I get famaliar because I know simple is best.

Code:
Sub PrinterSlct()
Application.Dialogs(xlDialogPrinterSetup).Show
End Sub
 
Upvote 0
Glad you sorted it (I like the ability to show dialogs too - I use it regularly for picking folders if you want to perform a file search on a specified folder). From those two lists you provided, I believe your colleague has "hp color LaserJet 4600" on Ne04 rather than Ne05 as you have (hence the problem). You could, if you wished, test this by amending the location in your original code and then seeing if it runs on her computer without fault. Without the Printer dialog, therefore, you would need to perform an analysis within your code to establish if the user has the relevant printer set up on their computer and also where it is set up and modify your code accordingly.
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,575
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top