You are here:

Microsoft Word/VB Script in Excel to Format TextBox in Word


Hi Aidan,

I am having issues with figuring out how to use VB Script to edit a TextBox in Word. To truly clarify what I am trying to do, the script is actually located in Excel. When some action is performed in Excel it will load a new Word document, copy a picture from Excel into Word, create a new TextBox, position the TextBox over the picture, and place text in the TextBox.

So far I have all of this working. The part I am having issues with is changing this TextBox so there are no borders (which I am sure it is “line” in Word). I also want to set the TextBox to no fill. Granted by default it is no fill, but if someone has changed their default settings then it might be filled, so I want to force it to not be filled.

I have extensively search the Internet for many hours and asked this question in a few other forums, but nobody seems to have an answer on the borders and no fill. I am not sure if you have any ideas on how to do this either.

Here is the code that I have so far and it does work:

Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add


With wrdDoc.Shapes.AddTextBox(msoTextOrientationHorizontal, 200, 52, 96, 50)
End With

With wrdApp.Selection
  .TypeText Text:="My picture text"
End With

Remember, this code is in Excel and will make a new document in Word. This does everything that I listed in the 1st paragraph. Can you please take a look to see if you can figure out how to get this TextBox so it has no borders or fill? I know how to use VB Script to do all of this in Excel, but the code for Word is completely different and I spent hours trying to do everything I can possibly think of.

Thanks for any help you can provide,


Recording a macro in Word with the object selected is a good way to find out what is set - the bad news is that EVERYTHING gets recorded - also it uses Word Constants which are not necessarily word constants!  if you add

   .ShapeRange.Fill.Visible = 0
   .ShapeRange.Line.Visible = 0

to the with WrdApp.Selection section you should get what you want.   You MIGHT want to amend the way you get an instance of word as an object as your method starts an instance regardless of whether or not there is already one active

On Error GoTo notloaded
       Set WrdApp = GetObject(, "Word.Application")
       If Err.Number = 429 Then
         Set WrdWd = CreateObject("Word.Application")
       End If
       WrdWd.Visible = True
On Error GoTo 0

is the method I use which utilizes any existing copy of Word first.

About Microsoft Word
This topic answers questions related to Microsoft Word stand-alone or Microsoft Office Word including Word 2003, Word 2007, Office 2000, and Office XP. You can get Word help on formatting text, tables, tabs, fonts, styles, general Word layouts, bullets, headings, and outlines, using templates, toolbar modifications, and using Track Changes. You may also find tips on linking Word and Excel embedded objects including charts. This site does not provide a general Word tutorial nor the basics of using a word processor. It provides specific answers to using Microsoft Word only. If you do not see your Word question answered in this area then please ask a Word question here

Microsoft Word

All Answers

Answers by Expert:

Ask Experts


Aidan Heritage


I have provided first hand support since `95 for Microsoft Office majoring in Word and Excel - support for all versions of Word from 2 onwards

©2016 All rights reserved.