Re: Page Break in Excel from VB 2005



On Jul 9, 9:35 pm, "Stephen Plotnick" <the...@xxxxxxxxxxxxx> wrote:
I can't believe this simple problem...

I'm very new to VB...

My code is very similar but my initial DIM is here.

Public oexcel As ApplicationClass = Nothing

oexcel = New ApplicationClass()

Here is my line in the program.

obook.o***.HPageBreaks.Add(oexcel.Range("A72"))

Here is the exception.

System.MissingMemberException was unhandled
Message="Public member 'o***' on type 'WorkbookClass' not found."
Source="Microsoft.VisualBasic"
StackTrace:
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object
o, Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack)
at
Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at MeasureMonitorSpread***.Module1.Main() in
C:\Users\SP\Documents\Visual Studio
2005\Projects\MeasureMonitorSpread***\Module1.vb:line 565
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

"rowe_newsgroups" <rowe_em...@xxxxxxxxx> wrote in message

news:1184026941.595725.274080@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On Jul 9, 6:05 pm, "Stephen Plotnick" <the...@xxxxxxxxxxxxx> wrote:
obook.o***.HPageBreaks.Add(Excel.Range
("A72"))

I get the blue line under Excel.Range

Error 1 'Range' is a type in 'Excel' and cannot be used as an expression.

"rowe_newsgroups" <rowe_em...@xxxxxxxxx> wrote in message

news:1184005431.309811.162690@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On Jul 9, 1:18 pm, "Stephen Plotnick" <the...@xxxxxxxxxxxxx> wrote:
'o***.HPageBreaks.Add.Range("A72")
.

"rowe_newsgroups" <rowe_em...@xxxxxxxxx> wrote in message

news:1183999625.014207.264600@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On Jul 9, 12:43 pm, "Stephen Plotnick" <the...@xxxxxxxxxxxxx> wrote:
Seth,

THanks for the reply. That is what I did and I always get an
exception
at
run time. I googled and seemed to have tried everything and it
never
seems
to work.

Steve"rowe_newsgroups" <rowe_em...@xxxxxxxxx> wrote in message

news:1183998991.748123.138610@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On Jul 9, 12:24 pm, "Stephen Plotnick" <the...@xxxxxxxxxxxxx>
wrote:
I'm using VB 2005 and Excel 2007 and cannot figure out how to
insert a
page
break before line 72. I've tried several ways but always get an
exception
error.

Thanks in advance.

I would recommend you use the "Record Macro" functionality of
Excel
and record a macro of you adding the pagebreak. Then you just
have
to
modify that classic vb code to Visual Basic .Net and use it in
your
application.

Thanks,

Seth Rowe

Post your code.

Thanks,

Seth Rowe

You need to specify the range using the excel application object. The
following works fine (except for a late binding warning for using
HPageBreaks) for me:

Option Strict Off

'// Of course you'll need to reference
'// Microsoft Excel Object Library 12.0 for this to work
Imports Microsoft.Office.Interop.Excel

Module Module1

Sub Main()
Dim excel As New Application()
Dim workbook As Workbook = excel.Workbooks.Add()
workbook.Worksheets(1).HPageBreaks.Add(excel.Range("A5"))
excel.Visible = True
End Sub

End Module

Hope That Helps!

Thanks,

Seth Rowe- Hide quoted text -

- Show quoted text -

You looked at my code wrong - I used the instance "excel" not the type
"Excel." You need to use the instance of Excel.Application that you
use to create the excel workbooks.

Thanks,

Seth Rowe

I don't see where you dimension obook or o***. Could you please post
the entire code you use?

Thanks,

Seth Rowe

.