Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro to close workbook when file print is selected

Good morning; I am using Windows 2000 and Excel 2000.
I have the following macro for a read only file. The
Workbook file contains two worksheets. I need to prevent
users from printing either sheet since they are extremely
large, (2,000 pages). The macro is being executed but the
file still prints. What am I missing here?
Thanks
Phil

If ActiveWindow.SelectedSheets.PrintOut = True Then
MsgBox ("This File Is over 1,900 Pages and Too Large to
Print")
ActiveWorkbook.Close
End If
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Macro to close workbook when file print is selected

By the time your code tries to execute, the print has long since spooled off
to the queue. By then it's too late to intercept.

Are you using the BeforePrint event to capture the Print attempt? That's
the appropriate place to do so. Insert the line Cancel = True to abort
prints BEFORE they get to the queue.

In addition, I *think* there's a way to prevent sheets from being printed as
an option, but I may be wrong.

Randall Arnold

"Phil" wrote in message
...
Good morning; I am using Windows 2000 and Excel 2000.
I have the following macro for a read only file. The
Workbook file contains two worksheets. I need to prevent
users from printing either sheet since they are extremely
large, (2,000 pages). The macro is being executed but the
file still prints. What am I missing here?
Thanks
Phil

If ActiveWindow.SelectedSheets.PrintOut = True Then
MsgBox ("This File Is over 1,900 Pages and Too Large to
Print")
ActiveWorkbook.Close
End If
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macro to close workbook when file print is selected

If you don't want to use VBA
(user can open the file without macro's also)

You can also set the print range on each sheet to a1:a3 or so.
Then when they hit the print button only this cells are printed.


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Randall Arnold" wrote in message ...
By the time your code tries to execute, the print has long since spooled off
to the queue. By then it's too late to intercept.

Are you using the BeforePrint event to capture the Print attempt? That's
the appropriate place to do so. Insert the line Cancel = True to abort
prints BEFORE they get to the queue.

In addition, I *think* there's a way to prevent sheets from being printed as
an option, but I may be wrong.

Randall Arnold

"Phil" wrote in message
...
Good morning; I am using Windows 2000 and Excel 2000.
I have the following macro for a read only file. The
Workbook file contains two worksheets. I need to prevent
users from printing either sheet since they are extremely
large, (2,000 pages). The macro is being executed but the
file still prints. What am I missing here?
Thanks
Phil

If ActiveWindow.SelectedSheets.PrintOut = True Then
MsgBox ("This File Is over 1,900 Pages and Too Large to
Print")
ActiveWorkbook.Close
End If
End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Macro to close workbook when file print is selected

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
End Sub

Place this event in the Thisworkbook module and you can't print
as long the user is enabled macro's when opening the file

Right click on the Excel icon next to File in the menubar
Choose view code
paste this event there
Alt-Q to go back to Excel
Save the file


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Phil" wrote in message ...
Randall;
I tried something like this.
According to the VB help menu, it is supposed to abort the
print job but it is not.
When I run it the worksheet still prints.
Also, If you are referring to the "Tools-Options" in
Excel, I don't see anything that would prevent printing in
there.

Sub NoPrint()
ActiveWindow.SelectedSheets
Workbook_BeforePrint
Cancel = True
End Sub

Thanks
Phil

-----Original Message-----
By the time your code tries to execute, the print has

long since spooled off
to the queue. By then it's too late to intercept.

Are you using the BeforePrint event to capture the Print

attempt? That's
the appropriate place to do so. Insert the line Cancel =

True to abort
prints BEFORE they get to the queue.

In addition, I *think* there's a way to prevent sheets

from being printed as
an option, but I may be wrong.

Randall Arnold

"Phil" wrote in message
...
Good morning; I am using Windows 2000 and Excel 2000.
I have the following macro for a read only file. The
Workbook file contains two worksheets. I need to prevent
users from printing either sheet since they are

extremely
large, (2,000 pages). The macro is being executed but

the
file still prints. What am I missing here?
Thanks
Phil

If ActiveWindow.SelectedSheets.PrintOut = True Then
MsgBox ("This File Is over 1,900 Pages and Too Large to
Print")
ActiveWorkbook.Close
End If
End Sub




.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro to close workbook when file print is selected

Thanks Ron.

What I was not doing was saving the workbook, closing it
and then trying to print after re-opening.

-----Original Message-----
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
End Sub

Place this event in the Thisworkbook module and you can't

print
as long the user is enabled macro's when opening the file

Right click on the Excel icon next to File in the menubar
Choose view code
paste this event there
Alt-Q to go back to Excel
Save the file


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Phil" wrote in message

...
Randall;
I tried something like this.
According to the VB help menu, it is supposed to abort

the
print job but it is not.
When I run it the worksheet still prints.
Also, If you are referring to the "Tools-Options" in
Excel, I don't see anything that would prevent printing

in
there.

Sub NoPrint()
ActiveWindow.SelectedSheets
Workbook_BeforePrint
Cancel = True
End Sub

Thanks
Phil

-----Original Message-----
By the time your code tries to execute, the print has

long since spooled off
to the queue. By then it's too late to intercept.

Are you using the BeforePrint event to capture the

Print
attempt? That's
the appropriate place to do so. Insert the line

Cancel =
True to abort
prints BEFORE they get to the queue.

In addition, I *think* there's a way to prevent sheets

from being printed as
an option, but I may be wrong.

Randall Arnold

"Phil" wrote in message
...
Good morning; I am using Windows 2000 and Excel 2000.
I have the following macro for a read only file. The
Workbook file contains two worksheets. I need to

prevent
users from printing either sheet since they are

extremely
large, (2,000 pages). The macro is being executed but

the
file still prints. What am I missing here?
Thanks
Phil

If ActiveWindow.SelectedSheets.PrintOut = True Then
MsgBox ("This File Is over 1,900 Pages and Too Large

to
Print")
ActiveWorkbook.Close
End If
End Sub




.



.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Macro to close workbook when file print is selected

Beat me to it!

Of course, he'll want the IF/THEN logic as well, probably. But I'm betting
he can get it from here.

Randall

"Ron de Bruin" wrote in message
...
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
End Sub

Place this event in the Thisworkbook module and you can't print
as long the user is enabled macro's when opening the file

Right click on the Excel icon next to File in the menubar
Choose view code
paste this event there
Alt-Q to go back to Excel
Save the file


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Phil" wrote in message

...
Randall;
I tried something like this.
According to the VB help menu, it is supposed to abort the
print job but it is not.
When I run it the worksheet still prints.
Also, If you are referring to the "Tools-Options" in
Excel, I don't see anything that would prevent printing in
there.

Sub NoPrint()
ActiveWindow.SelectedSheets
Workbook_BeforePrint
Cancel = True
End Sub

Thanks
Phil

-----Original Message-----
By the time your code tries to execute, the print has

long since spooled off
to the queue. By then it's too late to intercept.

Are you using the BeforePrint event to capture the Print

attempt? That's
the appropriate place to do so. Insert the line Cancel =

True to abort
prints BEFORE they get to the queue.

In addition, I *think* there's a way to prevent sheets

from being printed as
an option, but I may be wrong.

Randall Arnold

"Phil" wrote in message
...
Good morning; I am using Windows 2000 and Excel 2000.
I have the following macro for a read only file. The
Workbook file contains two worksheets. I need to prevent
users from printing either sheet since they are

extremely
large, (2,000 pages). The macro is being executed but

the
file still prints. What am I missing here?
Thanks
Phil

If ActiveWindow.SelectedSheets.PrintOut = True Then
MsgBox ("This File Is over 1,900 Pages and Too Large to
Print")
ActiveWorkbook.Close
End If
End Sub




.





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro to close workbook when file print is selected

Got it!

I have a nice little message that pops up to inform the
user the file is too large to print.
Thanks much
Phil

-----Original Message-----
Beat me to it!

Of course, he'll want the IF/THEN logic as well,

probably. But I'm betting
he can get it from here.

Randall

"Ron de Bruin" wrote in message
...
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
End Sub

Place this event in the Thisworkbook module and you

can't print
as long the user is enabled macro's when opening the

file

Right click on the Excel icon next to File in the

menubar
Choose view code
paste this event there
Alt-Q to go back to Excel
Save the file


--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"Phil" wrote in message

...
Randall;
I tried something like this.
According to the VB help menu, it is supposed to

abort the
print job but it is not.
When I run it the worksheet still prints.
Also, If you are referring to the "Tools-Options" in
Excel, I don't see anything that would prevent

printing in
there.

Sub NoPrint()
ActiveWindow.SelectedSheets
Workbook_BeforePrint
Cancel = True
End Sub

Thanks
Phil

-----Original Message-----
By the time your code tries to execute, the print has
long since spooled off
to the queue. By then it's too late to intercept.

Are you using the BeforePrint event to capture the

Print
attempt? That's
the appropriate place to do so. Insert the line

Cancel =
True to abort
prints BEFORE they get to the queue.

In addition, I *think* there's a way to prevent

sheets
from being printed as
an option, but I may be wrong.

Randall Arnold

"Phil" wrote in message
...
Good morning; I am using Windows 2000 and Excel

2000.
I have the following macro for a read only file.

The
Workbook file contains two worksheets. I need to

prevent
users from printing either sheet since they are
extremely
large, (2,000 pages). The macro is being executed

but
the
file still prints. What am I missing here?
Thanks
Phil

If ActiveWindow.SelectedSheets.PrintOut = True Then
MsgBox ("This File Is over 1,900 Pages and Too

Large to
Print")
ActiveWorkbook.Close
End If
End Sub




.





.

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 to Close a specific workbook. Dmad11 Excel Discussion (Misc queries) 1 July 7th 09 09:28 PM
Macro to close workbook with prompt JMac[_2_] Excel Worksheet Functions 1 January 31st 08 05:29 PM
How do I print a workbook in but only print selected worksheets? Karl S. Excel Discussion (Misc queries) 1 August 31st 06 12:34 AM
Macro to include Close Print Preview Vic Charts and Charting in Excel 1 January 9th 06 01:06 AM
run macro on workbook close Nigel Excel Discussion (Misc queries) 3 November 29th 05 08:48 PM


All times are GMT +1. The time now is 04:14 AM.

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

About Us

"It's about Microsoft Excel"