Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Move page breaks programmatically...

I am trying to move page breaks in an Excel spreadsheet programmatically in
..NET, but I keep getting an error.

I am changing page breaks because there is some "heading" data on some rows
that should be kept with it's data, and if the page break occurs right after
the heading, I want to move it before the heading.

My code to change the page break's location is:

_pb.Location = (Excel.Range)_wksht.Cells[int.Parse(_rng.Row.ToString()),
"A"];

_rng.Row = 45
_rng is an Excel.Range object
_pb is one of the HPageBreaks in the spreadsheet

Error reported is:
Error code is -2146827284
Exception from HRESULT: 0x800A03EC.
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Excel.HPageBreak.set_Location(Range )
at STLTrust.Flash.Reports.PrintSpreadsheets(DateTime ReportDate) in
c:\projects\stltrust flash\reports.cs:line 679

Which, obviously, tells me nothing except that I got a COM error when
setting the location.

I have tried using a hard coded row, instead of the one from the _rng
object, since I thought maybe the problem was it wasn't getting the row from
the Range object, but I still got the error. (i.e. _pb.Location =
(Excel.Range)_wksht.Cells[45, "A"];)

If someone could PLEASE tell me what I am doing wrong here, I would really
appreciate it! Thanks!

Theresa Smallwood





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Move page breaks programmatically...

A long time ago I approached this same issue with a different approach.

1. Figured out the maximum number of rows per printed page.
2. Removed all page breaks (if they were hard coded to the sheet)
3. Loop down the rows with step = #1 (above)
tested that row for header
if no header, backed up a row at a time until a header was found
4. Hard coded a page break
5. Continue the loop until the end.

--
steveB

Remove "AYN" from email to respond
"Theresa Smallwood" wrote in message
...
I am trying to move page breaks in an Excel spreadsheet programmatically in
.NET, but I keep getting an error.

I am changing page breaks because there is some "heading" data on some
rows that should be kept with it's data, and if the page break occurs
right after the heading, I want to move it before the heading.

My code to change the page break's location is:

_pb.Location = (Excel.Range)_wksht.Cells[int.Parse(_rng.Row.ToString()),
"A"];

_rng.Row = 45
_rng is an Excel.Range object
_pb is one of the HPageBreaks in the spreadsheet

Error reported is:
Error code is -2146827284
Exception from HRESULT: 0x800A03EC.
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Excel.HPageBreak.set_Location(Range )
at STLTrust.Flash.Reports.PrintSpreadsheets(DateTime ReportDate) in
c:\projects\stltrust flash\reports.cs:line 679

Which, obviously, tells me nothing except that I got a COM error when
setting the location.

I have tried using a hard coded row, instead of the one from the _rng
object, since I thought maybe the problem was it wasn't getting the row
from the Range object, but I still got the error. (i.e. _pb.Location =
(Excel.Range)_wksht.Cells[45, "A"];)

If someone could PLEASE tell me what I am doing wrong here, I would really
appreciate it! Thanks!

Theresa Smallwood







  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Move page breaks programmatically...

Is there a way to figure out the max number of rows on a page
programmatically, or do I have to do that manually and "hard-code" that
value? And hope that no one changes the page size, or orientation, etc.?

And I would still like to know why my code is giving me an error. All the
examples I saw said I should be able to do this, and I want to know why I
can't.

Theresa

"STEVE BELL" wrote in message
news:BoRAe.16538$O56.164@trnddc07...
A long time ago I approached this same issue with a different approach.

1. Figured out the maximum number of rows per printed page.
2. Removed all page breaks (if they were hard coded to the sheet)
3. Loop down the rows with step = #1 (above)
tested that row for header
if no header, backed up a row at a time until a header was found
4. Hard coded a page break
5. Continue the loop until the end.

--
steveB

Remove "AYN" from email to respond
"Theresa Smallwood" wrote in message
...
I am trying to move page breaks in an Excel spreadsheet programmatically
in .NET, but I keep getting an error.

I am changing page breaks because there is some "heading" data on some
rows that should be kept with it's data, and if the page break occurs
right after the heading, I want to move it before the heading.

My code to change the page break's location is:

_pb.Location = (Excel.Range)_wksht.Cells[int.Parse(_rng.Row.ToString()),
"A"];

_rng.Row = 45
_rng is an Excel.Range object
_pb is one of the HPageBreaks in the spreadsheet

Error reported is:
Error code is -2146827284
Exception from HRESULT: 0x800A03EC.
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Excel.HPageBreak.set_Location(Range )
at STLTrust.Flash.Reports.PrintSpreadsheets(DateTime ReportDate) in
c:\projects\stltrust flash\reports.cs:line 679

Which, obviously, tells me nothing except that I got a COM error when
setting the location.

I have tried using a hard coded row, instead of the one from the _rng
object, since I thought maybe the problem was it wasn't getting the row
from the Range object, but I still got the error. (i.e. _pb.Location =
(Excel.Range)_wksht.Cells[45, "A"];)

If someone could PLEASE tell me what I am doing wrong here, I would
really appreciate it! Thanks!

Theresa Smallwood









  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Move page breaks programmatically...

If you use only automatic pagebreaks, then you can determine the number of
rows on a page by seeing where the automatic pagebreaks are located. Of
course the problem gets more complex if all the rows are not the same
height.

--
Regards,
Tom Ogilvy

"Theresa Smallwood" wrote in message
...
Is there a way to figure out the max number of rows on a page
programmatically, or do I have to do that manually and "hard-code" that
value? And hope that no one changes the page size, or orientation, etc.?

And I would still like to know why my code is giving me an error. All the
examples I saw said I should be able to do this, and I want to know why I
can't.

Theresa

"STEVE BELL" wrote in message
news:BoRAe.16538$O56.164@trnddc07...
A long time ago I approached this same issue with a different approach.

1. Figured out the maximum number of rows per printed page.
2. Removed all page breaks (if they were hard coded to the sheet)
3. Loop down the rows with step = #1 (above)
tested that row for header
if no header, backed up a row at a time until a header was found
4. Hard coded a page break
5. Continue the loop until the end.

--
steveB

Remove "AYN" from email to respond
"Theresa Smallwood" wrote in message
...
I am trying to move page breaks in an Excel spreadsheet programmatically
in .NET, but I keep getting an error.

I am changing page breaks because there is some "heading" data on some
rows that should be kept with it's data, and if the page break occurs
right after the heading, I want to move it before the heading.

My code to change the page break's location is:

_pb.Location =

(Excel.Range)_wksht.Cells[int.Parse(_rng.Row.ToString()),
"A"];

_rng.Row = 45
_rng is an Excel.Range object
_pb is one of the HPageBreaks in the spreadsheet

Error reported is:
Error code is -2146827284
Exception from HRESULT: 0x800A03EC.
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Excel.HPageBreak.set_Location(Range )
at STLTrust.Flash.Reports.PrintSpreadsheets(DateTime ReportDate) in
c:\projects\stltrust flash\reports.cs:line 679

Which, obviously, tells me nothing except that I got a COM error when
setting the location.

I have tried using a hard coded row, instead of the one from the _rng
object, since I thought maybe the problem was it wasn't getting the row
from the Range object, but I still got the error. (i.e. _pb.Location =
(Excel.Range)_wksht.Cells[45, "A"];)

If someone could PLEASE tell me what I am doing wrong here, I would
really appreciate it! Thanks!

Theresa Smallwood











  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Move page breaks programmatically...

Ok, I am trying this approach, and it puts the pagebreaks I want in, but I'm
having an issue with one thing - how do I remove the automatic pagebreaks?
When I try to loop through and Delete() them, I get a COM exception (similar
to the one I got with moving the page breaks.)

Theresa


"STEVE BELL" wrote in message
news:BoRAe.16538$O56.164@trnddc07...
A long time ago I approached this same issue with a different approach.

1. Figured out the maximum number of rows per printed page.
2. Removed all page breaks (if they were hard coded to the sheet)
3. Loop down the rows with step = #1 (above)
tested that row for header
if no header, backed up a row at a time until a header was found
4. Hard coded a page break
5. Continue the loop until the end.

--
steveB

Remove "AYN" from email to respond
"Theresa Smallwood" wrote in message
...
I am trying to move page breaks in an Excel spreadsheet programmatically
in .NET, but I keep getting an error.

I am changing page breaks because there is some "heading" data on some
rows that should be kept with it's data, and if the page break occurs
right after the heading, I want to move it before the heading.

My code to change the page break's location is:

_pb.Location = (Excel.Range)_wksht.Cells[int.Parse(_rng.Row.ToString()),
"A"];

_rng.Row = 45
_rng is an Excel.Range object
_pb is one of the HPageBreaks in the spreadsheet

Error reported is:
Error code is -2146827284
Exception from HRESULT: 0x800A03EC.
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Excel.HPageBreak.set_Location(Range )
at STLTrust.Flash.Reports.PrintSpreadsheets(DateTime ReportDate) in
c:\projects\stltrust flash\reports.cs:line 679

Which, obviously, tells me nothing except that I got a COM error when
setting the location.

I have tried using a hard coded row, instead of the one from the _rng
object, since I thought maybe the problem was it wasn't getting the row
from the Range object, but I still got the error. (i.e. _pb.Location =
(Excel.Range)_wksht.Cells[45, "A"];)

If someone could PLEASE tell me what I am doing wrong here, I would
really appreciate it! Thanks!

Theresa Smallwood











  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default Move page breaks programmatically...

Theresa,

Usually when you force a page break, the auto page breaks shift from the
inserted row to the
end of the document. You don't need to delete auto page breaks, just the
inserted ones you may have put in previously. (sorry if I mislead you)

In short - it shouldn't be an issue.

--
steveB

Remove "AYN" from email to respond
"Theresa Smallwood" wrote in message
...
Ok, I am trying this approach, and it puts the pagebreaks I want in, but
I'm having an issue with one thing - how do I remove the automatic
pagebreaks?
When I try to loop through and Delete() them, I get a COM exception
(similar to the one I got with moving the page breaks.)

Theresa


"STEVE BELL" wrote in message
news:BoRAe.16538$O56.164@trnddc07...
A long time ago I approached this same issue with a different approach.

1. Figured out the maximum number of rows per printed page.
2. Removed all page breaks (if they were hard coded to the sheet)
3. Loop down the rows with step = #1 (above)
tested that row for header
if no header, backed up a row at a time until a header was found
4. Hard coded a page break
5. Continue the loop until the end.

--
steveB

Remove "AYN" from email to respond
"Theresa Smallwood" wrote in message
...
I am trying to move page breaks in an Excel spreadsheet programmatically
in .NET, but I keep getting an error.

I am changing page breaks because there is some "heading" data on some
rows that should be kept with it's data, and if the page break occurs
right after the heading, I want to move it before the heading.

My code to change the page break's location is:

_pb.Location = (Excel.Range)_wksht.Cells[int.Parse(_rng.Row.ToString()),
"A"];

_rng.Row = 45
_rng is an Excel.Range object
_pb is one of the HPageBreaks in the spreadsheet

Error reported is:
Error code is -2146827284
Exception from HRESULT: 0x800A03EC.
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Excel.HPageBreak.set_Location(Range )
at STLTrust.Flash.Reports.PrintSpreadsheets(DateTime ReportDate) in
c:\projects\stltrust flash\reports.cs:line 679

Which, obviously, tells me nothing except that I got a COM error when
setting the location.

I have tried using a hard coded row, instead of the one from the _rng
object, since I thought maybe the problem was it wasn't getting the row
from the Range object, but I still got the error. (i.e. _pb.Location =
(Excel.Range)_wksht.Cells[45, "A"];)

If someone could PLEASE tell me what I am doing wrong here, I would
really appreciate it! Thanks!

Theresa Smallwood











  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Move page breaks programmatically...

To elaborate. If there is an automatic pagebreak, it is because the
parameters of your printer and the layout of the sheet dictate that a
pagebreak must be there. You eliminate an automatic pagebreak by putting a
manual pagebreak before the automatic pagebreak.

--
Regards,
Tom Ogilvy

"Theresa Smallwood" wrote in message
...
Ok, I am trying this approach, and it puts the pagebreaks I want in, but

I'm
having an issue with one thing - how do I remove the automatic pagebreaks?
When I try to loop through and Delete() them, I get a COM exception

(similar
to the one I got with moving the page breaks.)

Theresa


"STEVE BELL" wrote in message
news:BoRAe.16538$O56.164@trnddc07...
A long time ago I approached this same issue with a different approach.

1. Figured out the maximum number of rows per printed page.
2. Removed all page breaks (if they were hard coded to the sheet)
3. Loop down the rows with step = #1 (above)
tested that row for header
if no header, backed up a row at a time until a header was found
4. Hard coded a page break
5. Continue the loop until the end.

--
steveB

Remove "AYN" from email to respond
"Theresa Smallwood" wrote in message
...
I am trying to move page breaks in an Excel spreadsheet programmatically
in .NET, but I keep getting an error.

I am changing page breaks because there is some "heading" data on some
rows that should be kept with it's data, and if the page break occurs
right after the heading, I want to move it before the heading.

My code to change the page break's location is:

_pb.Location =

(Excel.Range)_wksht.Cells[int.Parse(_rng.Row.ToString()),
"A"];

_rng.Row = 45
_rng is an Excel.Range object
_pb is one of the HPageBreaks in the spreadsheet

Error reported is:
Error code is -2146827284
Exception from HRESULT: 0x800A03EC.
at System.RuntimeType.ForwardCallToInvokeMember(Strin g memberName,
BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&
msgData)
at Excel.HPageBreak.set_Location(Range )
at STLTrust.Flash.Reports.PrintSpreadsheets(DateTime ReportDate) in
c:\projects\stltrust flash\reports.cs:line 679

Which, obviously, tells me nothing except that I got a COM error when
setting the location.

I have tried using a hard coded row, instead of the one from the _rng
object, since I thought maybe the problem was it wasn't getting the row
from the Range object, but I still got the error. (i.e. _pb.Location =
(Excel.Range)_wksht.Cells[45, "A"];)

If someone could PLEASE tell me what I am doing wrong here, I would
really appreciate it! Thanks!

Theresa Smallwood











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
I can't move my page breaks in Page Break Preview btaft Excel Discussion (Misc queries) 6 April 27th 23 11:49 AM
Move page breaks Judy Excel Discussion (Misc queries) 1 June 23rd 05 11:44 PM
why can't I move page breaks? greensward Excel Discussion (Misc queries) 1 May 2nd 05 10:16 PM
why can't I move page breaks in XP Office greensward Excel Discussion (Misc queries) 0 May 2nd 05 02:38 PM
move page breaks Laura Excel Worksheet Functions 1 March 31st 05 02:16 AM


All times are GMT +1. The time now is 10:46 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"