How can a macro be created to insert a text box pre-populated with text in Word 2010?

6,216

This isn't specific to your VBA, because we don't know what it is, but below is how to add a textbox with text using VBA.

Sub addBox()
    Dim Box As Shape
    Set Box = ActiveDocument.Shapes.addTextBox( _
    Orientation:=msoTextOrientationHorizontal, _
    Left:=50, Top:=50, Width:=100, Height:=100)

    'This adds text to the box...
    Box.TextFrame.TextRange.Text = "Truck"
End Sub

source

Share:
6,216

Related videos on Youtube

JP LAW
Author by

JP LAW

Updated on September 18, 2022

Comments

  • JP LAW
    JP LAW over 1 year

    I am attempting to create a Macro to insert a textbox populated with predetermined text when a shortcut key is selected. I am able to record a Macro to generate the text but I am unable to get it to populate the text box with the text inside. For example, if I select Ctrl+Alt+T, a text box will be created with the word "truck" in it.

    Using Microsoft word 2010, how can I accomplish this?

    • CharlieRB
      CharlieRB over 9 years
      Welcome to Super User. You have done a good job of explaining what you are trying to do. Please edit your question to include the code you are currently working with and details of any research you have done. This will improve the quality of your question and the ability for others to give you a detailed answer.
  • JP LAW
    JP LAW over 9 years
    That is great, exactly what i was looking for. Many thanks