Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 98
Default Question with existing print macro

Hi I use the following macro below to print only desired sheets,


Sub PrintButton_Click()

'to start stop screen updating (stops screen flicker)
Application.ScreenUpdating = False

Sheets("Cover").Select
Application.Dialogs(xlDialogPrint).Show

Sheets("sheet2").Select
If Range("Calcs!i1") = True Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End If

Sheets("sheet3").Select
If Range("Calcs!f1") = True Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End If

'etc etc

End sub


This works as required!

This macro is linked to a control button, when pressed the user sees the
standard excel print screen where they can select their printer, and then
print, no problems. If however the user decides for some reason to then press
the cancel button, I you get a run error, I was wondering if it would be
possible such if they press cancel, it goes back to the sheet called cover
instead of getting the run error?
--
This post was created using recycled electrons!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,726
Default Question with existing print macro

I didn't get an error on printing, but why not just add the code to the
Beforeprint event, you can always set the Cancel argument then.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Newbeetle" wrote in message
...
Hi I use the following macro below to print only desired sheets,


Sub PrintButton_Click()

'to start stop screen updating (stops screen flicker)
Application.ScreenUpdating = False

Sheets("Cover").Select
Application.Dialogs(xlDialogPrint).Show

Sheets("sheet2").Select
If Range("Calcs!i1") = True Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End If

Sheets("sheet3").Select
If Range("Calcs!f1") = True Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End If

'etc etc

End sub


This works as required!

This macro is linked to a control button, when pressed the user sees the
standard excel print screen where they can select their printer, and then
print, no problems. If however the user decides for some reason to then
press
the cancel button, I you get a run error, I was wondering if it would be
possible such if they press cancel, it goes back to the sheet called cover
instead of getting the run error?
--
This post was created using recycled electrons!



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Question with existing print macro

I tried your code and clicked the cancel button. I didn't get an error because
of the cancel.

But I did get an error on the:
If Range("Calcs!i1") = True Then

This unqualified range refers to the worksheet that owns that code. And in this
case, I'm betting that it's not the Calcs worksheet.

There are a couple of different ways to fix it, but I like to qualify my ranges
this way:

Option Explicit
Sub PrintButton_Click()

Application.ScreenUpdating = False

Application.Dialogs(xlDialogPrint).Show

If Worksheets("Calcs").Range("i1") = True Then
Worksheets("Sheet2").PrintOut Copies:=1, preview:=True
End If

If Worksheets("Calcs").Range("f1") = True Then
Worksheets("sheet3").PrintOut Copies:=1, preview:=True
End If

Application.ScreenUpdating = True

End Sub

Note that you don't have to select the worksheet to print it.

And I added preview:=true for testing.

By the way, the unqualified range would refer to the activesheet in a general
module, but this code looks like it's behind the worksheet.

Newbeetle wrote:

Hi I use the following macro below to print only desired sheets,

Sub PrintButton_Click()

'to start stop screen updating (stops screen flicker)
Application.ScreenUpdating = False

Sheets("Cover").Select
Application.Dialogs(xlDialogPrint).Show

Sheets("sheet2").Select
If Range("Calcs!i1") = True Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End If

Sheets("sheet3").Select
If Range("Calcs!f1") = True Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End If

'etc etc

End sub

This works as required!

This macro is linked to a control button, when pressed the user sees the
standard excel print screen where they can select their printer, and then
print, no problems. If however the user decides for some reason to then press
the cancel button, I you get a run error, I was wondering if it would be
possible such if they press cancel, it goes back to the sheet called cover
instead of getting the run error?
--
This post was created using recycled electrons!


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 98
Default Question with existing print macro

Hi Guys,

You had me pondering there, anyway, I have done some checks printing, and I
found out I only get the error if printing to MS office image document writer
which I was using to test the program, if I print to a printer you can cancel
and its fine.

Any thoughts on stopping the error if used with this type of printer as some
of the guys will be using this printer on site to store the result
electronically?

Dave, thanks for the code, that is simpler and cuts down on a few lines
which is my aim now. Plan 1 was to get a working project then once I've
grasped it to try and cut down some of the code text.

Thanks to both of you.
--
This post was created using recycled electrons!


"Dave Peterson" wrote:

I tried your code and clicked the cancel button. I didn't get an error because
of the cancel.

But I did get an error on the:
If Range("Calcs!i1") = True Then

This unqualified range refers to the worksheet that owns that code. And in this
case, I'm betting that it's not the Calcs worksheet.

There are a couple of different ways to fix it, but I like to qualify my ranges
this way:

Option Explicit
Sub PrintButton_Click()

Application.ScreenUpdating = False

Application.Dialogs(xlDialogPrint).Show

If Worksheets("Calcs").Range("i1") = True Then
Worksheets("Sheet2").PrintOut Copies:=1, preview:=True
End If

If Worksheets("Calcs").Range("f1") = True Then
Worksheets("sheet3").PrintOut Copies:=1, preview:=True
End If

Application.ScreenUpdating = True

End Sub

Note that you don't have to select the worksheet to print it.

And I added preview:=true for testing.

By the way, the unqualified range would refer to the activesheet in a general
module, but this code looks like it's behind the worksheet.

Newbeetle wrote:

Hi I use the following macro below to print only desired sheets,

Sub PrintButton_Click()

'to start stop screen updating (stops screen flicker)
Application.ScreenUpdating = False

Sheets("Cover").Select
Application.Dialogs(xlDialogPrint).Show

Sheets("sheet2").Select
If Range("Calcs!i1") = True Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End If

Sheets("sheet3").Select
If Range("Calcs!f1") = True Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End If

'etc etc

End sub

This works as required!

This macro is linked to a control button, when pressed the user sees the
standard excel print screen where they can select their printer, and then
print, no problems. If however the user decides for some reason to then press
the cancel button, I you get a run error, I was wondering if it would be
possible such if they press cancel, it goes back to the sheet called cover
instead of getting the run error?
--
This post was created using recycled electrons!


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Question with existing print macro

Maybe trap for the error???

On Error Resume Next
Application.Dialogs(xlDialogPrint).Show
If Err.Number < 0 Then
'an error occurred
Err.Clear
'do what you want
exit sub '?
End If
On Error GoTo 0



Newbeetle wrote:

Hi Guys,

You had me pondering there, anyway, I have done some checks printing, and I
found out I only get the error if printing to MS office image document writer
which I was using to test the program, if I print to a printer you can cancel
and its fine.

Any thoughts on stopping the error if used with this type of printer as some
of the guys will be using this printer on site to store the result
electronically?

Dave, thanks for the code, that is simpler and cuts down on a few lines
which is my aim now. Plan 1 was to get a working project then once I've
grasped it to try and cut down some of the code text.

Thanks to both of you.
--
This post was created using recycled electrons!

"Dave Peterson" wrote:

I tried your code and clicked the cancel button. I didn't get an error because
of the cancel.

But I did get an error on the:
If Range("Calcs!i1") = True Then

This unqualified range refers to the worksheet that owns that code. And in this
case, I'm betting that it's not the Calcs worksheet.

There are a couple of different ways to fix it, but I like to qualify my ranges
this way:

Option Explicit
Sub PrintButton_Click()

Application.ScreenUpdating = False

Application.Dialogs(xlDialogPrint).Show

If Worksheets("Calcs").Range("i1") = True Then
Worksheets("Sheet2").PrintOut Copies:=1, preview:=True
End If

If Worksheets("Calcs").Range("f1") = True Then
Worksheets("sheet3").PrintOut Copies:=1, preview:=True
End If

Application.ScreenUpdating = True

End Sub

Note that you don't have to select the worksheet to print it.

And I added preview:=true for testing.

By the way, the unqualified range would refer to the activesheet in a general
module, but this code looks like it's behind the worksheet.

Newbeetle wrote:

Hi I use the following macro below to print only desired sheets,

Sub PrintButton_Click()

'to start stop screen updating (stops screen flicker)
Application.ScreenUpdating = False

Sheets("Cover").Select
Application.Dialogs(xlDialogPrint).Show

Sheets("sheet2").Select
If Range("Calcs!i1") = True Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End If

Sheets("sheet3").Select
If Range("Calcs!f1") = True Then
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End If

'etc etc

End sub

This works as required!

This macro is linked to a control button, when pressed the user sees the
standard excel print screen where they can select their printer, and then
print, no problems. If however the user decides for some reason to then press
the cancel button, I you get a run error, I was wondering if it would be
possible such if they press cancel, it goes back to the sheet called cover
instead of getting the run error?
--
This post was created using recycled electrons!


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 98
Default Question with existing print macro

Hi Dave,

Works a treat, thank you!
--
This post was created using recycled electrons!


"Dave Peterson" wrote:

Maybe trap for the error???

On Error Resume Next
Application.Dialogs(xlDialogPrint).Show
If Err.Number < 0 Then
'an error occurred
Err.Clear
'do what you want
exit sub '?
End If
On Error GoTo 0


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Help (Uppercase multiple ranges?) Ken Excel Discussion (Misc queries) 14 December 2nd 06 07:23 PM
Macro question Chris Excel Worksheet Functions 12 July 7th 06 01:23 AM
Error using a macro to print multiple pages. [email protected] Excel Discussion (Misc queries) 2 June 21st 06 06:47 AM
Macro question punter Excel Discussion (Misc queries) 10 June 12th 06 11:15 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM


All times are GMT +1. The time now is 03:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"