ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   error trapping (https://www.excelbanter.com/excel-programming/283501-error-trapping.html)

libby

error trapping
 
Hi
I'm having real trouble trapping this error.

I have a sub where the active printer is changed
Application.ActivePrinter = ListBox1.value

if the printer is networked then it works fine, but if it
isn't I get a run-time error 1004
Method 'ActivePrinter' of object'_Application' failed

Is there any way I can user On Error GoTo Errorhandler to
display the message "Printer Not Mapped" if this happpens?

Thanks in advance
Libby (xl97)

Don Guillett[_4_]

error trapping
 
post all of your code relating to this

--
Don Guillett
SalesAid Software

"libby" wrote in message
...
Hi
I'm having real trouble trapping this error.

I have a sub where the active printer is changed
Application.ActivePrinter = ListBox1.value

if the printer is networked then it works fine, but if it
isn't I get a run-time error 1004
Method 'ActivePrinter' of object'_Application' failed

Is there any way I can user On Error GoTo Errorhandler to
display the message "Printer Not Mapped" if this happpens?

Thanks in advance
Libby (xl97)




libby

error trapping
 
Hi

Well, there are many networked printers in our office and
I have created a form which has 5 of the most common ones
in it. When the user selects one, a label displays the
location of the printer in the office.
I've also so set it so that if the Active Printer for a
particular pc isn't in the listbox, then it's added to it.

There is a "Change" button on the form which changes the
active printer to one which the user has selected.

It all works fine if you have all the printers mapped to
your pc, but if you try and change the active printer to
one which is not mapped to your pc, then the run-time
error occurs.
I need to either map the printer (which I don't think is
possible)
or trap this error and go to an error handler which
displays an appropriate message.

The code for the Change button is
Application.ActivePrinter = listbox1.value

I can post more code if need be, but don't have it to hand
at present.

-----Original Message-----
post all of your code relating to this

--
Don Guillett
SalesAid Software

"libby" wrote in

message
...
Hi
I'm having real trouble trapping this error.

I have a sub where the active printer is changed
Application.ActivePrinter = ListBox1.value

if the printer is networked then it works fine, but if

it
isn't I get a run-time error 1004
Method 'ActivePrinter' of object'_Application' failed

Is there any way I can user On Error GoTo Errorhandler

to
display the message "Printer Not Mapped" if this

happpens?

Thanks in advance
Libby (xl97)



.


Dave Peterson[_3_]

error trapping
 
I think I'd just let them pick from one of their mapped printers using a builtin
dialog box:

Application.Dialogs(xlDialogPrinterSetup).Show

But if you know enough about the printers, you can connect them via your code.

I saved this example from a post in the scripting newsgroups:

Option Explicit
Sub testme02()
Dim WSH As Object
Dim PrinterPath As String
Dim PrinterDriver As String

Set WSH = CreateObject("WScript.Network")
PrinterPath = "\\printserver\printershare"
PrinterDriver = "HP LaserJet 4050 Series PS"

WSH.AddWindowsPrinterConnection PrinterPath, PrinterDriver
WSH.SetDefaultPrinter PrinterPath

End Sub



libby wrote:

Hi

Well, there are many networked printers in our office and
I have created a form which has 5 of the most common ones
in it. When the user selects one, a label displays the
location of the printer in the office.
I've also so set it so that if the Active Printer for a
particular pc isn't in the listbox, then it's added to it.

There is a "Change" button on the form which changes the
active printer to one which the user has selected.

It all works fine if you have all the printers mapped to
your pc, but if you try and change the active printer to
one which is not mapped to your pc, then the run-time
error occurs.
I need to either map the printer (which I don't think is
possible)
or trap this error and go to an error handler which
displays an appropriate message.

The code for the Change button is
Application.ActivePrinter = listbox1.value

I can post more code if need be, but don't have it to hand
at present.

-----Original Message-----
post all of your code relating to this

--
Don Guillett
SalesAid Software

"libby" wrote in

message
...
Hi
I'm having real trouble trapping this error.

I have a sub where the active printer is changed
Application.ActivePrinter = ListBox1.value

if the printer is networked then it works fine, but if

it
isn't I get a run-time error 1004
Method 'ActivePrinter' of object'_Application' failed

Is there any way I can user On Error GoTo Errorhandler

to
display the message "Printer Not Mapped" if this

happpens?

Thanks in advance
Libby (xl97)



.


--

Dave Peterson


Tom Ogilvy

error trapping
 
On Error goto ErrHandler
Application.ActivePrinter = listbox1.value
Exit Sub
ErrHandler:
msgbox err.number & vbNewLine & _
err.Description & vbNewline & vbNewLine & _
"This printer is not available"
End Sub

--
Regards,
Tom Ogilvy



libby wrote in message
...
Hi

Well, there are many networked printers in our office and
I have created a form which has 5 of the most common ones
in it. When the user selects one, a label displays the
location of the printer in the office.
I've also so set it so that if the Active Printer for a
particular pc isn't in the listbox, then it's added to it.

There is a "Change" button on the form which changes the
active printer to one which the user has selected.

It all works fine if you have all the printers mapped to
your pc, but if you try and change the active printer to
one which is not mapped to your pc, then the run-time
error occurs.
I need to either map the printer (which I don't think is
possible)
or trap this error and go to an error handler which
displays an appropriate message.

The code for the Change button is
Application.ActivePrinter = listbox1.value

I can post more code if need be, but don't have it to hand
at present.

-----Original Message-----
post all of your code relating to this

--
Don Guillett
SalesAid Software

"libby" wrote in

message
...
Hi
I'm having real trouble trapping this error.

I have a sub where the active printer is changed
Application.ActivePrinter = ListBox1.value

if the printer is networked then it works fine, but if

it
isn't I get a run-time error 1004
Method 'ActivePrinter' of object'_Application' failed

Is there any way I can user On Error GoTo Errorhandler

to
display the message "Printer Not Mapped" if this

happpens?

Thanks in advance
Libby (xl97)



.




libby

error trapping
 
Thanks guys!
-----Original Message-----
On Error goto ErrHandler
Application.ActivePrinter = listbox1.value
Exit Sub
ErrHandler:
msgbox err.number & vbNewLine & _
err.Description & vbNewline & vbNewLine & _
"This printer is not available"
End Sub

--
Regards,
Tom Ogilvy



libby wrote in

message
...
Hi

Well, there are many networked printers in our office

and
I have created a form which has 5 of the most common

ones
in it. When the user selects one, a label displays the
location of the printer in the office.
I've also so set it so that if the Active Printer for a
particular pc isn't in the listbox, then it's added to

it.

There is a "Change" button on the form which changes the
active printer to one which the user has selected.

It all works fine if you have all the printers mapped to
your pc, but if you try and change the active printer to
one which is not mapped to your pc, then the run-time
error occurs.
I need to either map the printer (which I don't think is
possible)
or trap this error and go to an error handler which
displays an appropriate message.

The code for the Change button is
Application.ActivePrinter = listbox1.value

I can post more code if need be, but don't have it to

hand
at present.

-----Original Message-----
post all of your code relating to this

--
Don Guillett
SalesAid Software

"libby" wrote in

message
...
Hi
I'm having real trouble trapping this error.

I have a sub where the active printer is changed
Application.ActivePrinter = ListBox1.value

if the printer is networked then it works fine, but

if
it
isn't I get a run-time error 1004
Method 'ActivePrinter' of object'_Application' failed

Is there any way I can user On Error GoTo

Errorhandler
to
display the message "Printer Not Mapped" if this

happpens?

Thanks in advance
Libby (xl97)


.



.



All times are GMT +1. The time now is 10:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com