Format Text Box Before outputting it

P

Phil Stanton

New to VBA for word though I have some experience in VBA for Access.

I want to place formatted text boxes on a document . If I use something like

Sub DrawTextBox()

ActiveDocument.Shapes.AddTextbox _
(msoTextOrientationHorizontal, 100, 100, 100, 80).Select

Selection.ShapeRange.Select
With Selection.ShapeRange
.TextFrame.MarginLeft = 0#
.TextFrame.MarginRight = 0#
.TextFrame.MarginTop = 0#
.TextFrame.MarginBottom = 0#
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor = RGB(255, 0, 0)
.Fill.Transparency = 0#
.Line.Transparency = 0#
.Line.Visible = msoTrue
.Line.DashStyle = msoLineSquareDot
.Line.Weight = 5
.Line.Style = msoLineSingle
.Line.ForeColor = wdBlue
End With

With Selection.Font
.NameAscii = "Arial"
.Size = 16
.Bold = True
.Italic = False
.Underline = True
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = RGB(0, 0, 0)
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
' Center
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.TypeText Text:="This is a Text Box"
Selection.Collapse

End Sub


The problem is that each bit of formatting takes place sequentially, and
outputting 50 or 100 text boxes takes a few minutes to complete

I feel there should be a way of defining the text box properties BEFORE
Adding it to the document

Something like (I know none of this works)

Dim MyTextBox as TextBox
With MyTextBox
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor = RGB(255, 0, 0)
.Fill.Transparency = 0#
.Line.Transparency = 0#
.Line.Visible = msoTrue
.Line.DashStyle = msoLineSquareDot
.Line.Weight = 5
.Line.Style = msoLineSingle
.Line.ForeColor = wdBlue
End With

Set MyTextBox = ActiveDocument.Shapes.AddTextbox _
(msoTextOrientationHorizontal, 100, 100, 100, 80)

This seems to work as another alternative UNTIL I get to trying to output it
to the document


Public Type MyTextBox ' Create user-defined type.
FillColour As Long ' Define elements of data
type.
BorderColour As Long
BorderWidth As Integer
ForeColour As Long
End Type

Function CreateTextBox()

Dim MTB As MyTextBox ' Declare variable.
Dim MyDocument As Document
Dim MyTB As TextFrame
Dim TextBox1 As Shape
Dim NewShape As Shape

With MTB
.BorderColour = wdBlack
.BorderWidth = 6
.FillColour = RGB(255, 0, 0)
.ForeColour = wdWhite
End With

??????????????? Output

Thanks for any help

Phil
 

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