#1
|
|||
|
|||
Get Name of Selected/Active Form Field
Greetings,
I have a protected document with several text form fields. I need to create a macro that will allow a user to change the text font color to red of the selected or active form field. Similarly, I need a macro that will allow a user to highlight the text of the selected/active form field. I'm pretty well versed in Excel vba, but Word vba is new to me - so any help is appreciated! |
#2
|
|||
|
|||
|
#3
|
|||
|
|||
Thanks. I tried this, but it's still not working.
Code:
Private Sub CommandButton1111_Click() Dim Name As String If Selection.FormFields.Count = 1 Then Name = Selection.FormFields(1).Name ElseIf Selection.FormFields.Count = 0 And Selection.Bookmarks.Count > 0 Then Name = Selection.Bookmarks(Selection.Bookmarks.Count).Name End If MsgBox Name If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect End If ActiveDocument.Bookmarks(Name).Select Selection.Font.Color = wdColorRed Selection.Collapse Direction:=wdCollapseEnd If ActiveDocument.ProtectionType = wdNoProtection Then ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True End If End Sub |
#4
|
|||
|
|||
Your code copied and pasted into a new document with a formfield selected works fine here. Have you somehow deleted the bookmark?
|
#5
|
|||
|
|||
Nope, my bookmarks are there. Would you be able to attached your test document so I can see it working? Perhaps that will help me locate the problem.
|
#6
|
|||
|
|||
I don't think you can upload docm files here. See: https://dl.dropboxusercontent.com/u/64545773/Demo.docm
|
#7
|
|||
|
|||
Thanks! I see it working now. But when I add more form fields, it will only make the font of "Text1" red, not the selected form field. Any ideas?
|
#8
|
|||
|
|||
That is not the case here. Msgbox and font coloring affects the selected formfield:
https://dl.dropboxusercontent.com/u/64545773/Demo.docm |
#9
|
|||
|
|||
How are you adding the other formfields? Hopefully not by copying and pasting. Because that does not copy over any bookmarks.
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mandatory field in a form | thedeadzeds | Word | 1 | 05-09-2013 03:27 PM |
Form field selection allows entry into form text box | David C | Word | 1 | 10-24-2012 04:53 AM |
Can't tab from field to field in form | Lynieee | Word | 6 | 06-18-2012 02:37 PM |
Form Fields - Create blank form text field with if statement? | LAssist2011 | Word | 5 | 12-14-2011 03:02 PM |
Form Field Shading. | Ninerhoss | Word | 0 | 11-23-2010 02:40 PM |