Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default How to insert a page break in Excel VBA

Hi,

I want to insert a page break after a condition has been met. I created a
recorded macro to see what the code looks like then I inserted it into my
real code but got an error

Here is a snippet of the real code:
=================================
If recordCounter = 8 Then

ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=ActiveCell
'Sheets("output").Cells(rowNum, colNum).Value="TEXT TEST"
recordCounter = 0
End If
===========================================

I know the rest of the code except for the HPageBreak statement is good
since I tested it before pasting the statement in...I tested it using the
"TEXT TEST" and it did insert sample text..but instead of inserting sample
text at Cell location (rownum, colNum) I want to insert a page break...

Any suggestions...thanks much for any help with this!!!

Craig

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to insert a page break in Excel VBA

If your activecell is in row 1, you're going to have trouble.

Where is that activecell?

if activecell.row = 1 then
'do nothing
else
ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=ActiveCell
end if

And the next question is: Are you sure you want to be depending on the
activecell?

Craig wrote:

Hi,

I want to insert a page break after a condition has been met. I created a
recorded macro to see what the code looks like then I inserted it into my
real code but got an error

Here is a snippet of the real code:
=================================
If recordCounter = 8 Then

ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=ActiveCell
'Sheets("output").Cells(rowNum, colNum).Value="TEXT TEST"
recordCounter = 0
End If
===========================================

I know the rest of the code except for the HPageBreak statement is good
since I tested it before pasting the statement in...I tested it using the
"TEXT TEST" and it did insert sample text..but instead of inserting sample
text at Cell location (rownum, colNum) I want to insert a page break...

Any suggestions...thanks much for any help with this!!!

Craig


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to insert a page break in Excel VBA


Seems like the same topic ...

Why would this statement

ActiveSheet.HPageBreaks.Add Befo="B53"

generate a the run-time error shown in the screenshot?

Thanks,

- A

+-------------------------------------------------------------------
|Filename: HPageBreaks_Resize Error.bmp
|Download: http://www.excelforum.com/attachment.php?postid=4090
+-------------------------------------------------------------------

--
GoFigur
-----------------------------------------------------------------------
GoFigure's Profile: http://www.excelforum.com/member.php...nfo&userid=427
View this thread: http://www.excelforum.com/showthread.php?threadid=49000

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to insert a page break in Excel VBA

You may want to type that run time error into your message. Lots of people
don't go through excelforum and can't see your screen image.

GoFigure wrote:

Seems like the same topic ...

Why would this statement

ActiveSheet.HPageBreaks.Add Befo="B53"

generate a the run-time error shown in the screenshot?

Thanks,

- Al

+-------------------------------------------------------------------+
|Filename: HPageBreaks_Resize Error.bmp |
|Download: http://www.excelforum.com/attachment.php?postid=4090 |
+-------------------------------------------------------------------+

--
GoFigure
------------------------------------------------------------------------
GoFigure's Profile: http://www.excelforum.com/member.php...fo&userid=4274
View this thread: http://www.excelforum.com/showthread...hreadid=490001


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to insert a page break in Excel VBA


Thanks, Dave.

Here's what's in that tiny image:

"Run-time error '-13':

Type mismatch"

Thanks for any help.

- A

--
GoFigur
-----------------------------------------------------------------------
GoFigure's Profile: http://www.excelforum.com/member.php...nfo&userid=427
View this thread: http://www.excelforum.com/showthread.php?threadid=49000



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to insert a page break in Excel VBA

Ahh. I should have looked more closely:

ActiveSheet.HPageBreaks.Add Befo=ActiveSheet.Range("B53")

when you did this:
ActiveSheet.HPageBreaks.Add Befo="B53"

That "b35" doesn't mean anything more than a string to excel. It would be like:

ActiveSheet.HPageBreaks.Add Befo="goFigure"



GoFigure wrote:

Thanks, Dave.

Here's what's in that tiny image:

"Run-time error '-13':

Type mismatch"

Thanks for any help.

- Al

--
GoFigure
------------------------------------------------------------------------
GoFigure's Profile: http://www.excelforum.com/member.php...fo&userid=4274
View this thread: http://www.excelforum.com/showthread...hreadid=490001


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to insert a page break in Excel VBA


Thanks, Dave.

- Al


--
GoFigure
------------------------------------------------------------------------
GoFigure's Profile: http://www.excelforum.com/member.php...fo&userid=4274
View this thread: http://www.excelforum.com/showthread...hreadid=490001

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default How to insert a page break in Excel VBA

This info you sent me Dave, could just get me over the "hump" Thanks!!!

"Dave Peterson" wrote:

If your activecell is in row 1, you're going to have trouble.

Where is that activecell?

if activecell.row = 1 then
'do nothing
else
ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=ActiveCell
end if

And the next question is: Are you sure you want to be depending on the
activecell?

Craig wrote:

Hi,

I want to insert a page break after a condition has been met. I created a
recorded macro to see what the code looks like then I inserted it into my
real code but got an error

Here is a snippet of the real code:
=================================
If recordCounter = 8 Then

ActiveWindow.SelectedSheets.HPageBreaks.Add Befo=ActiveCell
'Sheets("output").Cells(rowNum, colNum).Value="TEXT TEST"
recordCounter = 0
End If
===========================================

I know the rest of the code except for the HPageBreak statement is good
since I tested it before pasting the statement in...I tested it using the
"TEXT TEST" and it did insert sample text..but instead of inserting sample
text at Cell location (rownum, colNum) I want to insert a page break...

Any suggestions...thanks much for any help with this!!!

Craig


--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to insert a page break in Excel VBA

Ah, there's always another hump on that horizon.

Craig wrote:

This info you sent me Dave, could just get me over the "hump" Thanks!!!

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
Excel 2007 Page Break Adjustments causes a page break each cell BKaufman Excel Worksheet Functions 2 September 10th 10 05:02 AM
Excel: How do you insert an automatic page break after each row? tjw Excel Discussion (Misc queries) 1 January 15th 08 10:21 PM
Excel 2003 SP2 - Insert | Page Break doesn't work Michelle Excel Discussion (Misc queries) 1 October 17th 07 09:35 AM
Automatically insert page break every 6 rows in excel doc Icetea Excel Discussion (Misc queries) 1 October 10th 05 11:55 AM
Insert Page Break Don Excel Discussion (Misc queries) 3 June 9th 05 08:32 PM


All times are GMT +1. The time now is 09:52 PM.

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"