Thread: Print code
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Print code

First, I didn't go back to the xlm help to find out what those parms mean in the
xl4 macro line. In fact, I'd record a new macro that gave me the code in
"normal" VBA.

But if you don't want to try that, you could try:

Option Explicit
Sub testme()
Dim iCtr As Long
Dim FoundIt As Boolean
Dim CurPrinter As String

CurPrinter = Application.ActivePrinter

FoundIt = False
For iCtr = 0 To 99
On Error Resume Next
Application.ActivePrinter = "\\mrafp1\MRA-ADMINCP1 on Ne" _
& Format(iCtr, "00") & ":"
If Err.Number = 0 Then
FoundIt = True
Exit For
Else
'keep looking
Err.Clear
End If
Next iCtr
On Error GoTo 0

If FoundIt = False Then
MsgBox "No printer close to that name"
Else
'do the real work
ExecuteExcel4Macro _
"PRINT(1,,,1,,,,,,,,2,""" & ActivePrinter.Name _
& """,,TRUE,,FALSE)"
'and change it back
Application.ActivePrinter = CurPrinter
End If
End Sub

=======
If you're just printing the activesheet, the code could be as simple as:


If FoundIt = False Then
MsgBox "No printer close to that name"
Else
'do the real work
activesheet.printout
'and change it back
Application.ActivePrinter = CurPrinter
End If
Very Basic User wrote:

Hello,
I have a marco recorded to print a selection of sheets. The printer being
used is on a network and not my default printer. When I create the code on
my PC, it works fine, but as soon as another user tries to use the code from
their PC it won't work. Code is attached below, when I tried to create the
code on another PC, the section Ne04 in both lines is the only thing that
changed. Is there a common statement that could make this work regardless of
the PC from which I'm opening the file?

Application.ActivePrinter = "\\mrafp1\MRA-ADMINCP1 on Ne04:"
ExecuteExcel4Macro _
"PRINT(1,,,1,,,,,,,,2,""\\mrafp1\MRA-ADMINCP1 on
Ne04:"",,TRUE,,FALSE)"

--
Thank you for your time!
John


--

Dave Peterson