Printing Problem

R

RMS

I have two shared printers on two seperate hard wired networked, desktop
computers. One prints tractor fed labels for Serums, and one prints
instructions on regular letter paper.

The patient information is entered on a laptop which connects wirelessly to
the newtork. I use an Excel Macro assigned to two different buttons to
select the proper printer and the range to print. This setup works
great....Until I introduce a second laptop, using the same Excel version
(2007) and same code.

Both laptops access each printer perfectly for printing the "Test Page".
However the Printer Macros on one or the other laptops fails to work. If I
re-record the marcos they work again. (Manual Printing works fine always)

On careful examination of the macro code, I find that the "ne03", for
example, has changed to "ne05" in the new code on the printer line. What
would be a strategy to avoid having to re-record the macros?

Thanks-a very puzzled RMS
 
L

Leo Mazzi

Well I could find several solutions to your problem. For example this is a
part of code that by "brute force" selects the propper printer:
(from: http://www.tek-tips.com/viewthread.cfm?qid=879030)
---

Function NetworkPrinter(ByVal myprinter As String)
On Error Resume Next
Dim NetWork As Variant
Dim X As Integer
'/// Define NetWork Array \\\
NetWork = Array("Ne00:", "Ne01:", "Ne02:", "Ne03:", "Ne04:", _
"Ne05:", "Ne06:", "Ne07:", "Ne08:", _
"Ne09:", "Ne10:", "Ne11:", "Ne12:", _
"Ne13:", "Ne14:", "Ne15:", "Ne16:", _
"LPT1:", "LPT2:", "File:", "SMC100:")
'Setup printer to Print
X = 0
TryAgain:
On Error Resume Next
'Printer
Application.ActivePrinter = myprinter & Prt_On & NetWork(X)
If Err.Number <> 0 And X < 16 Then
X = X + 1
GoTo TryAgain
ElseIf Err.Number <> 0 And X > 15 Then
GoTo PrtError
End If
On Error GoTo 0
NetworkPrinter = myprinter & Prt_On & NetWork(X)
errorExit:
Exit Function
PrtError:
'no printer found
NetworkPrinter = ""
Resume errorExit
End Function

---
So the idea here would be that you instead of setting dirrectly the name,
invoke this function with just the printer name,

but maybe a better approach would be to check for the name in the list of
printers. How to get a list of printers? Try analyze this code - you can
modify it easily to return the propper name...
(from http://www.ozgrid.com/forum/showthread.php?t=20182)
---
Sub get_printers()

On Error Resume Next

Set WshNetwork = CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
For i = 0 To oPrinters.Count - 1 Step 1
Cells(i + 1, 1) = " Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i + 1)
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top