PC Review


Reply
Thread Tools Rate Thread

Beforeprint not executing

 
 
Salgud
Guest
Posts: n/a
 
      18th Nov 2010
I'm missing something simple. I have the following code in ThisWorkbook:

Private Sub Workbook_BeforePrint(Cancel As Boolean)

ActiveSheet.PageSetup.PrintArea = ActiveCell.CurrentRegion.Address

End Sub

But it's not happening, just prints the selected cell instead of the
Current Region. An Edit Goto Current Region selects the correct Current
Region. I copied the code from an online tutorial, and read a reviewed the
VBA Help, and can't figure out what's wrong. I'm in Win2000, XL2003.
Anybody see what I'm missing?

TIA
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      18th Nov 2010
I tested your code by adding a couple of lines and then trying to print.
It won't actually print anything, it just tells you what the print area is.
Give it a try, maybe it will provide a clue...
'---
Private Sub Workbook_BeforePrint(Cancel As Boolean)
ActiveSheet.PageSetup.PrintArea = ActiveCell.CurrentRegion.Address
MsgBox ActiveSheet.PageSetup.PrintArea
Cancel = True
End Sub
'---
And...
The Before_Print event only fires once and the code you have only
applies to the sheet you are looking at when you hit the print button.
If you are printing multiple sheets and want a particular cells current
region to print on each sheet, then you will need different code.
--
Jim Cone
Portland, Oregon USA
http://www.mediafire.com/PrimitiveSoftware

..
..
..

"Salgud" <(E-Mail Removed)>
wrote in message
news:59nqq5x145ak$.(E-Mail Removed)...
I'm missing something simple. I have the following code in ThisWorkbook:

Private Sub Workbook_BeforePrint(Cancel As Boolean)

ActiveSheet.PageSetup.PrintArea = ActiveCell.CurrentRegion.Address

End Sub

But it's not happening, just prints the selected cell instead of the
Current Region. An Edit Goto Current Region selects the correct Current
Region. I copied the code from an online tutorial, and read a reviewed the
VBA Help, and can't figure out what's wrong. I'm in Win2000, XL2003.
Anybody see what I'm missing?

TIA
 
Reply With Quote
 
Don Guillett Excel MVP
Guest
Posts: n/a
 
      19th Nov 2010
On Nov 18, 4:23*pm, "Jim Cone" <james.cone...@comcast.netXXX> wrote:
> I tested your code by adding a couple of lines and then trying to print.
> It won't actually print anything, it just tells you what the print area is.
> Give it a try, maybe it will provide a clue...
> '---
> Private Sub Workbook_BeforePrint(Cancel As Boolean)
> ActiveSheet.PageSetup.PrintArea = ActiveCell.CurrentRegion.Address
> MsgBox ActiveSheet.PageSetup.PrintArea
> Cancel = True
> End Sub
> '---
> And...
> The Before_Print event only fires once *and the code you have only
> applies to the sheet you are looking at when you hit the print button.
> If you are printing multiple sheets and want a particular cells current
> region to print on each sheet, then you will need different code.
> --
> Jim Cone
> Portland, Oregon *USAhttp://www.mediafire.com/PrimitiveSoftware
>
> .
> .
> .
>
> "Salgud" <spamboy6...@comcast.net>
> wrote in messagenews:59nqq5x145ak$.(E-Mail Removed)...
> I'm missing something simple. I have the following code in ThisWorkbook:
>
> Private Sub Workbook_BeforePrint(Cancel As Boolean)
>
> * * ActiveSheet.PageSetup.PrintArea = ActiveCell.CurrentRegion.Address
>
> End Sub
>
> But it's not happening, just prints the selected cell instead of the
> Current Region. An Edit Goto Current Region selects the correct Current
> Region. I copied the code from an online tutorial, and read a reviewed the
> VBA Help, and can't figure out what's wrong. I'm in Win2000, XL2003.
> Anybody see what I'm missing?
>
> TIA

From the vba help index xl2003

CurrentRegion Property
See AlsoApplies ToExampleSpecificsReturns a Range object that
represents the current region. The current region is a range bounded
by any combination of blank rows and blank columns. Read-only.

Remarks
This property is useful for many operations that automatically expand
the selection to include the entire current region, such as the
AutoFormat method.

This property cannot be used on a protected worksheet.

Example
This example selects the current region on Sheet1.

Worksheets("Sheet1").Activate
ActiveCell.CurrentRegion.Select

This example assumes that you have a table on Sheet1 that has a header
row. The example selects the table, without selecting the header row.
The active cell must be somewhere in the table before you run the
example.

Set tbl = ActiveCell.CurrentRegion
tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1, _
tbl.Columns.Count).Select

 
Reply With Quote
 
Salgud
Guest
Posts: n/a
 
      19th Nov 2010
Thanks to both of you for your replies. The problem was that I had XL
re-installed some time back, hadn't been doing any macros since, and had
macro security set to High (default), so no macros could run!

Thanks again.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
BeforePrint robzrob Microsoft Excel Programming 0 14th Dec 2009 10:37 PM
BeforePrint =?Utf-8?B?Um9iaW4gQ2xheQ==?= Microsoft Excel Programming 6 13th Feb 2007 03:48 PM
BeforePrint help =?Utf-8?B?Um9va2llIDFzdCBjbGFzcw==?= Microsoft Excel Programming 4 19th Nov 2005 09:57 PM
BeforePrint Add In =?Utf-8?B?RGFuaWVsIE1jQ29sbGljaw==?= Microsoft Excel Programming 10 10th Jun 2005 08:09 PM
ADO 2.7 & ADO 2.8 beforeprint =?Utf-8?B?SkNhbnlvbmVlcg==?= Microsoft Excel Programming 8 30th Mar 2005 04:05 PM


Features
 

Advertising
 

Newsgroups
 


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