Setting textbox margin properties via VBA

A

Alcide

Hello All,

I generally prefer my textbox margins to be zero and I'd like to create a
macro to do that. So far I have the following code:

Sub FormatTextBox()
Dim myShape As Shape
Dim myPage As Page
For Each myPage In ActiveDocument.Pages
For Each myShape In myPage.Shapes
With myShape
.MarginBottom = 0
.MarginTop = 0
.MarginRight = 0
.MarginLeft = 0




End With

Next myShape

Next myPage
End Sub

It compiles but doesn't work.

What am I missing here?
My appreciation in advance for your assistance.
 
E

Ed Bennett

Alcide said:
I generally prefer my textbox margins to be zero and I'd like to
create a macro to do that. So far I have the following code:

The most important thing to mention with Publisher programming is your
Publisher version - Publisher 2003 has a very different object model to
Publisher 2002.

Next, you need to take a look at your VBA Help Files.
These are located in:
c:\Program Files\Microsoft Office\Office11\1033\VBAPB10.CHM

(For a default English-language install of Publisher 2003. Substitute
Office11 with Office10 for Publisher 2002, 1033 is the US English language
ID)

Looking here, you see that there is no such property of the Shape object as
MarginTop (ditto MarginLeft, marginRight, MarginBottom).
The Margin properties are actually properties of the TextFrame object (which
is more reasonable, as only text frame objects will have this property - not
all shapes).
The TextFrame property of the Shape object returns the TextFrame object that
applies to that shape.

You will need to change "With myShape" to "With myShape.TextFrame"

You will also need to add some error-handling code, as you will encounter
errors if you try to use .TextFrame for a myShape that does not have a text
frame.
 
S

Selmasgem

Ed Bennett said:
The most important thing to mention with Publisher programming is your
Publisher version - Publisher 2003 has a very different object model to
Publisher 2002.

Next, you need to take a look at your VBA Help Files.
These are located in:
c:\Program Files\Microsoft Office\Office11\1033\VBAPB10.CHM

(For a default English-language install of Publisher 2003. Substitute
Office11 with Office10 for Publisher 2002, 1033 is the US English language
ID)

Looking here, you see that there is no such property of the Shape object as
MarginTop (ditto MarginLeft, marginRight, MarginBottom).
The Margin properties are actually properties of the TextFrame object (which
is more reasonable, as only text frame objects will have this property - not
all shapes).
The TextFrame property of the Shape object returns the TextFrame object that
applies to that shape.

You will need to change "With myShape" to "With myShape.TextFrame"

You will also need to add some error-handling code, as you will encounter
errors if you try to use .TextFrame for a myShape that does not have a text
frame.

How do you change margin sizes for pictures, not text in Publisher 2003? By
margins, I mean printable area.
 
E

Ed Bennett

Selmasgem said:
How do you change margin sizes for pictures, not text in Publisher 2003? By
margins, I mean printable area.

The printable area is determined by your printer, and is the same for
both pictures and text.

This discussion was on setting the distance between the edge of the text
in a text box and the edge of the text box. Nothing to do with printable
area.

Read http://ed.mvps.org/Static.aspx?=Publisher/FAQs (last-but-one entry)
and http://ed.mvps.org/Static.aspx?=Publisher/horidiag.
 

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