Macro recording does not work with Text Box, please help (Word 200

M

Mike

Hi! I am trying to programmatically create a text box with certain colors and
fill effects and properties.

So far, for everything I had to create I recorded a Macro and then saw what
I had to do by looking at the generated code.

With the textbox insertion, I am unable to record a macro. The mouse cursor
changes as when the macro is being recorded, but the textbox is not being
drawn. I also can not seem to find any documentation on how to do so in VBA
or VSTO.

What am I doing wrong?
Please help.

Many thanks in advance,
 
M

Mike

Thank you very much for taking a look. So, it still possible to produce a
text box programmatically ?
 
J

Jay Freedman

Hi Mike,

Yes, it is possible to add a textbox programmatically. It just isn't
possible to record the macro.

In the VBA help, look up the AddTextBox method as applied to the
Shapes object. Here's a sample to get you started:

Sub Add_TextBox()
Dim myTextBox As Shape

Set myTextBox = ActiveDocument.Shapes.AddTextbox( _
Orientation:=msoTextOrientationHorizontal, _
Left:=InchesToPoints(1.5), _
Top:=InchesToPoints(2#), _
Width:=InchesToPoints(3.25), _
Height:=InchesToPoints(3.25), _
Anchor:=Selection.Range)

With myTextBox.Fill
.ForeColor.RGB = RGB(128, 0, 0)
.BackColor.RGB = RGB(170, 120, 220)
.TwoColorGradient msoGradientHorizontal, 2
End With

With myTextBox.TextFrame.TextRange
.Text = "Hello!"
.Font.Name = "Comic Sans MS"
.Font.Size = 24
.Bold = True
End With
End Sub
 
G

Graham Mayor

An alternative is to save the preformatted box as an autotext entry and
insert that.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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