[VBA with word] adding shapes to pages

G

Giuliano

Hi,

I have some problems that I'm not able to solve.

1) I have a doc and I need to add some pages to it. In each page I want to
add a shape (rectangle). Here the code I use

Set rangeSection = ThisDocument.Sections(2).Range
rangeSection.EndOf wdSection, wdMove
[cut]
For l = 1 To iMissingPages
rangeSection.EndOf wdSection, wdMove
rangeSection.InsertBreak (wdPageBreak)
rangeSection.EndOf wdSection, wdMove
MsgBox rangeSection.Information(wdActiveEndAdjustedPageNumber)
Set rcRect = ThisDocument.Shapes.AddShape(msoShapeRectangle, 0,
0, 10, 10, rangeSection)
[cut]

this code is ok (it does what I want) but if I remove the msgbox line it
doesn't. Why ?

2) now I need to change the trasparency of the shape but I can't find the
property/method to do that. I've found "....fill.trasparency" but I need the
(right click)->shapes->color and lines>color -> no fill (I don't know if
this is translated correctly) where is it ?

3) finally I need to change the size to cover the whole page (the document
is 2 pages per sheet)....
rcRect.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
rcRect.RelativeVerticalPosition = wdRelativeVerticalPositionPage
sBordo = MillimetersToPoints(1)
rcRect.Left = (ThisDocument.PageSetup.LeftMargin - sBordo)
rcRect.Top = (ThisDocument.PageSetup.TopMargin - sBordo)
rcRect.Width = (ThisDocument.PageSetup.PageWidth -
ThisDocument.PageSetup.LeftMargin - ThisDocument.PageSetup.RightMargin +
(sBordo * 2))
rcRect.Height = (ThisDocument.PageSetup.PageHeight -
ThisDocument.PageSetup.TopMargin - ThisDocument.PageSetup.BottomMargin +
(sBordo * 2))

but it seems that the width is the full page (not divided by 2 as it
should be).
The strange thing is that if this code is executed inside a
macro ->macro->run ... it's ok, but if this is executed by a form the
problem arise

I'm sorry for the bad translation but I hope to be clear

Thanks
Giuliano
 
C

Cindy Meister -WordMVP-

Hi Giuliano,

(1)
this code is ok (it does what I want) but if I remove the msgbox line it
doesn't.
HOW does it not work?

(2)
t I need the
(right click)->shapes->color and lines>color -> no fill
Try: rcRect.Fill.Visible = False

3) finally I need to change the size to cover the whole page (the document
is 2 pages per sheet)....
but it seems that the width is the full page (not divided by 2 as it
should be).
I don't see anywhere in your code where you divide by 2. How are you setting
up the document so that it "knows" you're making 2 pages / sheet? I know of
no method in Word that supports anything like this.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

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

Giuliano

Hi Cindy,

| (1)
| HOW does it not work?

Well without msgbox I see that the 2 pages are added to the end of the
section, but the shapes are in the last page (the one I had before adding
pages) and the first rect is over the second (I really see 1 rect and moving
the first I see the 2nd under it)

| (2)
| Try: rcRect.Fill.Visible = False

It works ! but really I never thought that visible method could be the one I
was looking for (usually visible stand for "visible")

| 3)
| I don't see anywhere in your code where you divide by 2. How are you
setting
| up the document so that it "knows" you're making 2 pages / sheet? I know
of
| no method in Word that supports anything like this.
|
Yes, really I meant that the document has two pages in one sheet (when I
print it) File->property (tag borders pages).
But....... I tryed again and ...... I noticed the when I call the macro, it
doesn't changes the width (the shape becomes larger and then it return to
the original size in a very short time). I can't explain why and what I
really saw before. Now I'll add the divide by 2

Thanks again
Giuliano
 
C

Cindy Meister -WordMVP-

Hi Giuliano,
| (1)
| HOW does it not work?

Well without msgbox I see that the 2 pages are added to the end of the
section, but the shapes are in the last page (the one I had before adding
pages) and the first rect is over the second (I really see 1 rect and moving
the first I see the 2nd under it)
Looking at your code, without the For...Next loop, I'd expect the SHAPE to be
inserted on the second page of the section. I don't see in the sample code for
(1) where more than one shape is being inserted?

Is there a rectangle already present in the document when you start? And
that's being moved "down"? If you click on this rectangle, and the "Object
anchors" option is activated in Tools/Options/View, next to which paragraph is
it anchored?

I suspect the problem may be that you're actually "pushing" the anchors to the
next page using the Page Break, since you appear to be anchoring them to the
end of the section. I'd make sure you have an "independent" paragraph between
page breaks, and that the drawing object is anchored to that. Very roughly:

--- Page break ---

--- Page Break ---

--- Section break ---

Dim rngAnchor as Word.Range
'blah-blah

Set rangeSection = ThisDocument.Sections(2).Range
rangeSection.EndOf wdSection, wdMove
[cut]
For l = 1 To iMissingPages
rangeSection.EndOf wdSection, wdMove
rangeSection.InsertParagraph
Set rngAnchor = rangeSection.DUPLICATE
rangeSection.Collapse wdCollapseEnd
rangeSection.InsertBreak (wdPageBreak)
rangeSection.EndOf wdSection, wdMove
Set rcRect = ThisDocument.Shapes.AddShape(msoShapeRectangle, 0,
0, 10, 10, rngAnchor)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

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

Giuliano

[cut ]

| I suspect the problem may be that you're actually "pushing" the anchors to
the
| next page using the Page Break, since you appear to be anchoring them to
the
| end of the section. I'd make sure you have an "independent" paragraph
between
| page breaks, and that the drawing object is anchored to that.

[cut]

Hi Cindy,

I think you're right, but I followed a different way to achieve it. Since I
already have a shape in each doc page and I would like to add the same shape
to the new pages, I simply anchored the shape to the header of the page. So,
when I insert a page break, the shape is automatically added to each new
page. Doing this thing I even solved another problem tied to anchor, when I
had a table in a whole page, the shape was anchored to the first cell of the
table, and I didn't be able to adjust the shape (the top, left are relative
to the table even if I specify absolute position of the page/margin).

Many many thanks again for your support
Giuliano
 
C

Cindy Meister -WordMVP-

Hi Giuliano,
Since I
already have a shape in each doc page and I would like to add the same shape
to the new pages, I simply anchored the shape to the header of the page.
Oh, yes, if you want the SAME picture on EVERY page, this is definitely the
way to go!

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top