View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Theresa Smallwood Theresa Smallwood is offline
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