How to change the size of a text box on a page

R

Robert L. Sullivan

I am writing a macro to change the size of a textbox that already exists on a
page to match the top and bottom margins on that page. I could not find a
specific example from the posts. Any help would be appreciated.

Regards,
Bob
 
R

Robert L. Sullivan

I figured out how to do it.

some background. My customer creates proposals with both potrait and
landscape pages. They want to have the footer consisently placed as their
prospect reads the proposal. Thus, the footer needs to be placed in the left
margin of a landscape page, rather than at the bottom, so it will look
consistent as their prospect reads the document. The "landscape footer" is
stored as an autotext entry, with boilerplate text, preset tab stops, and
PAGE field. The first version of the template assumed a set page margin.
However, some of their prospects require specific margins.

In retrospect, it may have been easier for me to create the landscape footer
textbox from scratch in code rather then mucking with the existing one.

Here is the code I came up with. If the page margins were set to something
very large, the tab stops would probably need adjusting, but I consider this
unlikely to happen. This code also assumes that there is only 1 textbox on
the page.

btw. the textbox contains...

"Company name <tab><tab>Chapter 1<tab>PAGE" where PAGE= a field


Selection.Range, RichText:=True
' 10/26/2006 - rls
'Adjust size and position of landscape footer (which is actually a textbox
that
'was created as an autotext entry) to fit any adjustments made to layout
'when document was created
'
Selection.Bookmarks("\Page").Range.Select
Set myRange = Selection.Range
Selection.Collapse

'Height of the text box equals height of the landscape page minus the margins.
With Selection.PageSetup
sngTextBoxHeight = (.PageHeight - (.BottomMargin + .TopMargin))
'Top of the textbox is just the top margin
sngTextBoxTop = .TopMargin
End With
For Each myShape In myRange.ShapeRange
If myShape.Type = msoTextBox Then
With myShape
strtemp = .TextFrame.TextRange.Text
.Height = sngTextBoxHeight
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Top = sngTextBoxTop
'set tab stops so that page number field is .02" from right edge
'of text box and "Chapter 1" is 1" from right edge.
.TextFrame.ContainingRange.Select
With Selection.ParagraphFormat.TabStops
.ClearAll
.Add Position:=InchesToPoints(0.5), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
.Add Position:=InchesToPoints(0.75), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
.Add Position:=InchesToPoints(1), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
.Add Position:=InchesToPoints(1.25), _
Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
.Add Position:=(sngTextBoxHeight - InchesToPoints(1)), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
.Add Position:=(sngTextBoxHeight - InchesToPoints(0.02)), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
End With
Selection.Collapse
End With
End If
Next myShape
myRange.Collapse
 

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