Unable to insert a page break AFTER a newly grouped graphics

W

Wai

Hi,

I have created a graphics consisting of lines and curves using VBA and
grouped all the items. I wish to insert a page break immediately AFTER the
grouped items using VBA (e.g. InsertBreak Type:=wdPageBreak). However, I
failed to do so. The grouped items went to the beginning of the next page as
well. Below is a summary of the codes:

*********************************************************
ActiveDocument.Shapes.AddLine(10, 20, 30, 100).Name = “Line1â€
…Add more lines

Set c = ActiveDocument.Shapes.BuildFreeform(msoEditingCorner, 30,40)
c.AddNodes msoSegmentCurve, msoEditingAuto, 60, 100
…Add more nodes
c.ConvertToShape.Select
set c=nothing

For Each shp In ActiveDocument.Shapes
ActiveDocument.Shapes.Range(Array(…)).Group.Name = “NewGroupâ€
Next

*********************************************************

Please advise
Wai
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?V2Fp?=,

The problem is that every Shape is anchored to a paragraph of text, and will
always be on the same page as that text. You don't specify the Anchor property,
so Word is free to anchor the Shape to anything it wishes - from your
description probably the last paragraph mark on the page. So when you insert
the page break the paragraph with the anchor is moving to the next page, taking
the Shapes with it.

You want to make sure you set the anchoring range to a paragraph higher up on
the page.
I have created a graphics consisting of lines and curves using VBA and
grouped all the items. I wish to insert a page break immediately AFTER the
grouped items using VBA (e.g. InsertBreak Type:=wdPageBreak). However, I
failed to do so. The grouped items went to the beginning of the next page as
well. Below is a summary of the codes:

*********************************************************
ActiveDocument.Shapes.AddLine(10, 20, 30, 100).Name = “Line1â€
…Add more lines

Set c = ActiveDocument.Shapes.BuildFreeform(msoEditingCorner, 30,40)
c.AddNodes msoSegmentCurve, msoEditingAuto, 60, 100
…Add more nodes
c.ConvertToShape.Select
set c=nothing

For Each shp In ActiveDocument.Shapes
ActiveDocument.Shapes.Range(Array(…)).Group.Name = “NewGroupâ€
Next

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
W

Wai

Hi Cindy,

This time I added two more lines of codes at the end:
ActiveDocument.Range.GoTo wdGoToSection, wdGoToLast
Selection.InsertBreak Type:=wdPageBreak
Then I began with a New Document;
Entered “carriage return†four times (five lines appeared in the doucment);
Moved to the beginning of the document;
Ran the codes to draw & group the graphics and insert a page break.

What I oberved was:
(a) After running the codes below, the graphics were drawn
*********************************************************
ActiveDocument.Shapes.AddLine(10, 20, 30, 100).Name = “Line1â€
…Add more lines

Set c = ActiveDocument.Shapes.BuildFreeform(msoEditingCorner, 30,40)
c.AddNodes msoSegmentCurve, msoEditingAuto, 60, 100
…Add more nodes
c.ConvertToShape.Select
set c=nothing
*********************************************************
It was found that all the five signs of carriage return were below the
graphics.

(b) After running the codes below, the graphics were grouped together and
the signs of carriage return went to the right side of the graphics.
*********************************************************
For Each shp In ActiveDocument.Shapes
ActiveDocument.Shapes.Range(Array(…)).Group.Name = “NewGroupâ€
Next
*********************************************************

(c) After running the codes below, a page break was inserted, the graphics
still went to the second page, leaving four signs of carriage return in the
first page and one in second page(on the right side of the graphics).
*********************************************************
ActiveDocument.Range.GoTo wdGoToSection, wdGoToLast
Selection.InsertBreak Type:=wdPageBreak
*********************************************************

How can I anchor the whole group of graphics to the first line of the
document and insert a page break after the last line using VBA?
Please advise
 
C

Cindy M.

Hi =?Utf-8?B?V2Fp?=,

You still aren't specifying the ANCHOR argument when adding a Shape to the
document. Take a good look at the Help topics for the methods you're using, such
as AddLine. There's a fifth argument named Anchor that tells VBA with which range
the Shape should be associated.

For example, since you're starting at the beginning of the document with
additional paragraph marks:
Dim rng as Word.Range

Set rng = Selection.Range
ActiveDocument.Shapes.AddLine(10, 20, 30, 100, rng).Name = "Line1"
This time I added two more lines of codes at the end:
ActiveDocument.Range.GoTo wdGoToSection, wdGoToLast
Selection.InsertBreak Type:=wdPageBreak
Then I began with a New Document;
Entered “carriage return†four times (five lines appeared in the doucment);
Moved to the beginning of the document;
Ran the codes to draw & group the graphics and insert a page break.

What I oberved was:
(a) After running the codes below, the graphics were drawn
*********************************************************
ActiveDocument.Shapes.AddLine(10, 20, 30, 100).Name = “Line1â€
…Add more lines

Set c = ActiveDocument.Shapes.BuildFreeform(msoEditingCorner, 30,40)
c.AddNodes msoSegmentCurve, msoEditingAuto, 60, 100
…Add more nodes
c.ConvertToShape.Select
set c=nothing
*********************************************************
It was found that all the five signs of carriage return were below the
graphics.

(b) After running the codes below, the graphics were grouped together and
the signs of carriage return went to the right side of the graphics.
*********************************************************
For Each shp In ActiveDocument.Shapes
ActiveDocument.Shapes.Range(Array(…)).Group.Name = “NewGroupâ€
Next
*********************************************************

(c) After running the codes below, a page break was inserted, the graphics
still went to the second page, leaving four signs of carriage return in the
first page and one in second page(on the right side of the graphics).
*********************************************************
ActiveDocument.Range.GoTo wdGoToSection, wdGoToLast
Selection.InsertBreak Type:=wdPageBreak
*********************************************************

How can I anchor the whole group of graphics to the first line of the
document and insert a page break after the last line using VBA?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
Top