#1
|
|||
|
|||
Find textbox name
I'm looking for a way to find the name of a textbox with VBA by placing the cursor in that textbox. Possible? Thanks in advance.
|
#2
|
|||
|
|||
What kind of textbox?
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oCC As ContentControl Dim oILS As InlineShape 'A formfield If Selection.FormFields.Count = 1 Then MsgBox Selection.FormFields(1).Name ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0 Then MsgBox Selection.Bookmarks(Selection.Bookmarks.Count).Name End If 'A content control For Each oCC In ActiveDocument.Range.ContentControls If Selection.Range.InRange(oCC.Range) Then MsgBox oCC.Title Next oCC 'A activeX control For Each oILS In ActiveDocument.InlineShapes If Selection.Range.InRange(oILS.Range) Then MsgBox oILS.OLEFormat.Object.Name End If Next End Sub |
#3
|
|||
|
|||
The textboxes I am working with are called VBA textboxes and not a Windows Form textbox. I hope that answers your question, or feel free and ask again. Thanks, this will be a big help.
|
#4
|
|||
|
|||
I just tried the above posted procedure and no result.
|
#5
|
|||
|
|||
Well, if it is a textbox in a Userform, you pretty much have to know the name before you can do anything with it. For example, if you have a textbox named TextBox1, then you could use the Enter event for the named control:
Private Sub TextBox1_Enter() MsgBox Me.TextBox1.Name End Sub |
#6
|
|||
|
|||
I think you had better tell us where these textboxes are, in the document or on a userform. Greg's original question has not been answered. Are they fomfields - these ARE called textboxes you know. ActiveX textboxes...also called textboxes. Or maybe even content controls which sometimes are called textboxes as well.
Oh and they can all be thought of as "VBA textboxes". |
#7
|
|||
|
|||
I can say with a certain large degree of certainty that they are probably not fomfields ;-)
With my legendary carelessness with typos and spelling, it is refreshing to know that the realm of imperfection is not a population of 1. |
#8
|
|||
|
|||
Oh I don't know. Things seem rather mushy, so they are all FOAMfields.
|
#9
|
||||
|
||||
Quote:
http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
I will try to clarify the textboxes I am using. They are created in Office 2010 vba from the userform where I click the textbox control from the toolbox. Thank you for your input. I want to check into your last posting identified as Selection_Change event macro. Best regards, Hdata
|
#11
|
||||
|
||||
In your previous reply, you said:
Quote:
Quote:
Code:
Private Sub TextBox1_Enter() MsgBox Me.ActiveControl.Name End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
I created a command button on the userform and attached the code below:
Code:
Private Sub cmdTextBoxName_Enter() MsgBox Me.ActiveControl.Name End Sub "cmdTextBoxName" The name of the textbox is actually "Document_City" What am I missing? Thank you for your response Hdata |
#13
|
|||
|
|||
IF you want the textbox to return its name when you click in it use:
Private Sub Document_City_Enter() MsgBox Me.Document_City.Name End Sub as previously provided, or Private Sub Document_City_Enter() MsgBox Me.ActiveConrol.Name End Sub as Paul provides, or If you click a command button Document_City obviously no longer has the focus so: Private Sub cmdTextBoxName_Enter() MsgBox Me.ActiveControl.Name End Sub Naturally returns cmdTextBoxName, because cmdTextBoxName is now the active control. |
#14
|
|||
|
|||
OK, as previously indicated, I have to know the name before I can do anything with it, which defeats what I was trying to do. So thanks again, I will move on to other issues.
|
#15
|
||||
|
||||
Well, your sub's name (cmdTextBoxName_Enter) shows that the control's name can only be 'cmdTextBoxName'. Evidently, you want something else; perhaps the name of a visually-related label. If so, unless the label and control are grouped (and nothing else is in the same group), there is no 100% reliable way for VBA to identify which one you want.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
clip art with embeded textbox | Mel Spence | Misc | 0 | 05-19-2013 09:38 AM |
Display result in textbox based on the input of another textbox | scarymovie | Word VBA | 5 | 05-16-2012 07:05 PM |
textbox color issue | Dave Duncan | Word | 0 | 08-07-2011 10:38 AM |
Textbox Template | t0m46 | Word | 0 | 09-07-2010 03:38 AM |
Creating Chart using VB textbox value | shyler82 | Word VBA | 0 | 03-12-2010 06:56 PM |