PDA

View Full Version : Insert SectionBreak from Coding in Excel



jazzyt2u
08-05-2008, 01:21 PM
Hi,

How do I insert a section break from excel after I have pasted a picture? Also how do I remove it if I don't need it.

The following isn't working:




Worksheets("DC1Chart").Range(rngT100, rng110).CopyPicture xlScreen, xlBitmapoDoc.Bookmarks("DownCompar1").Range.Select
oWord.Selection.PasteAndFormat Type:=wdFormatOriginalFormatting
oWord.InsertBreak Type:=wdSectionBreakNextPage




I also tried oDoc.InsertBreak Type:=wdSectionBreakNextPage

lucas
08-06-2008, 07:37 PM
maybe:

Selection.InsertBreak Type:=wdSectionBreakNextPage

a with statement for oWord might let you do all of the operations in one statement too.......not sure without seeing your document.

jazzyt2u
08-12-2008, 11:30 AM
Thank you.

Do you know how to select a certain header to change a word using oWord if I can get to the specific page using bookmarks?

macropod
08-13-2008, 03:43 AM
Hi Jazzyt2u,

Try something based on:
Sub UpdatePageHeader()
Dim MyRange As Range
Dim i As Integer
i = 10 ' change to suit
Set MyRange = ActiveDocument.Range(0, 0)
Set MyRange = MyRange.GoTo(What:=wdGoToPage, Name:=i)
MyRange.Select
With ActiveWindow
If .View.SplitSpecial <> wdPaneNone Then .Panes(2).Close
With .ActivePane.View
If .Type = wdNormalView Or .Type = wdOutlineView Then .Type = wdPrintView
.SeekView = wdSeekCurrentPageHeader
'Do Header stuff here
.SeekView = wdSeekMainDocument
End With
End With
End Sub

jazzyt2u
08-13-2008, 10:02 AM
Hi Lucus,

I tried

oWord.Selection.InsertBreak Type:=wdSectionBreakNextPage

and it didn't work.

oDoc.Bookmarks("DemoTable").Range.Select
Worksheets("DemoTable").Range(rngTD130, rngTD140).CopyPicture xlScreen, xlBitmap
oWord.Selection.PasteAndFormat Type:=wdFormatOriginalFormatting
oWord.Selection.TypeParagraph
oWord.Selection.InsertBreak Type:=wdSectionBreakNextPage

I get the following error when it gets to the last line of code above:
Run-Time Error '9118':
Parameter value was out of acceptable range

jazzyt2u
08-13-2008, 10:05 AM
Hi Macropod,

Will the code you provided work with the coding being in excel? Also, I'm not really sure what each line of code does.... well some of it yes... but most no...
Can you add comments on the end of the lines...sorry not real clear on this header stuff and not good at coding word at all.