PDA

View Full Version : Put Name of Textbox into Textbox



Benjamin_
01-18-2012, 07:24 AM
Hello,

i have a word document with many textboxes. Now i need the name of each textbox. (Textbox 1...n)

I've found the following Macro but it doesnt work..


Option Explicit
Option compare Text
Sub main()
Dim f As Field
Dim tb As TextBox
For Each f In ThisDocument.Fields
If f.OLEFormat Is Nothing Then ' do nothing
Else
If f.OLEFormat.ClassType = "Forms.Textbox.1" Then ' it is a textbox
Set tb = f.OLEFormat.Object
tb.Text = tb.Name
End If
End If ' f.oleformat is nothing
Next f
End Sub


Any Ideas ? I'm using Microsoft Word 2010

Thank you !

rruckus
01-23-2012, 02:34 PM
TextBoxes don't have a name property, so you cannot get it. It's hard to give a solution without knowing WHY you want the name, but if you want, you can use the .InlineShape.AlternativeText property to store a name-like property.

ActiveDocument.Fields(1).InlineShape.AlternativeText = "My First Field"