Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adjust margins of textbox after AddTextBox 1

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
I am building a word document from within VB. I am successfully adding Textboxes at predetermined locations on the page using the AddTextBox method on a shapes collection.

However, how do I set the internal margins for the textbox? I also want to be able to change the line colour, fill colour etc but the margins are the most important.

Thanks in advance.
 
Try something like the following:
Code:
Sub AddTextBox()
Dim txtNew As Shape

   Set txtNew = ThisDocument.Shapes.AddTextBox(msoTextOrientationHorizontal, 100, 50, 72, 16)
   [highlight]With txtNew[/highlight]
     [highlight].TextFrame.MarginLeft = 1.44  'value in points[/highlight]
     [highlight].TextFrame.MarginRight = 1.44[/highlight]
     [highlight].TextFrame.MarginTop = 2.16[/highlight]
     [highlight].TextFrame.MarginBottom = 2.16[/highlight]
     [highlight].Fill.ForeColor.RGB = RGB(200, 200, 200)[/highlight]
     [highlight].Line.ForeColor.RGB = RGB(255, 0, 0)[/highlight]
   [highlight]End With[/highlight]
End Sub


Regards,
Mike
 
Mike the question was dealing with properties AFTER the object was created. It is fairly straightforward doing properties setting at the time of creation. However, it is very very ugly in there, this part of the object model, afterwards.

Even properly selecting the right object can be tricky. Afterall, if the very first thing you do is add a textbox (a CanvasShape textbox, Insert > Textbox), the name of the object is "Canvas 3". Weird in there.

Gerry
See my Paintings and Sculpture
 
No Mike has hit the nail on the head - that's precisely what I was after.

Thanks so much!
 
Ah, I did not pay attention to the "adding" a textbox. As I posted, it is fairly straightforward setting margin at the moment of creating the textbox. It is a pain doing it after.

Glad it is working for you.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top