Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 219
Default Beforeprint not executing

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Beforeprint not executing

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"
wrote in message
...
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default Beforeprint not executing

On Nov 18, 4:23*pm, "Jim Cone" 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"
wrote in messagenews:59nqq5x145ak$.l7ztxf1watr5.dlg@40tude. net...
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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 219
Default Beforeprint not executing

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
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
BeforePrint robzrob Excel Programming 0 December 14th 09 10:37 PM
BeforePrint joeeng Excel Programming 1 November 7th 08 11:17 AM
BeforePrint Robin Clay Excel Programming 4 February 13th 07 03:48 PM
ADO 2.7 & ADO 2.8 beforeprint JCanyoneer Excel Programming 7 March 30th 05 04:05 PM
Help with BeforePrint Eric[_7_] Excel Programming 2 October 9th 03 07:44 PM


All times are GMT +1. The time now is 06:50 PM.

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"