Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-20-2014, 02:31 PM
NumberCruncher NumberCruncher is offline Get Name of Selected/Active Form Field Windows XP Get Name of Selected/Active Form Field Office 2003
Novice
Get Name of Selected/Active Form Field
 
Join Date: Jan 2014
Posts: 4
NumberCruncher is on a distinguished road
Default 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!
Reply With Quote
  #2  
Old 01-20-2014, 04:32 PM
gmaxey gmaxey is offline Get Name of Selected/Active Form Field Windows 7 32bit Get Name of Selected/Active Form Field Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,437
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

http://word.mvps.org/FAQs/TblsFldsFm...rFmFldName.htm
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 01-20-2014, 04:44 PM
NumberCruncher NumberCruncher is offline Get Name of Selected/Active Form Field Windows XP Get Name of Selected/Active Form Field Office 2003
Novice
Get Name of Selected/Active Form Field
 
Join Date: Jan 2014
Posts: 4
NumberCruncher is on a distinguished road
Default

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
I'm getting RunTime error 5941 "The requested member of the collection does not exist." And the line "ActiveDocument.Bookmarks(Name).Select" is Highlighted
Reply With Quote
  #4  
Old 01-20-2014, 04:49 PM
gmaxey gmaxey is offline Get Name of Selected/Active Form Field Windows 7 32bit Get Name of Selected/Active Form Field Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,437
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Your code copied and pasted into a new document with a formfield selected works fine here. Have you somehow deleted the bookmark?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 01-20-2014, 04:54 PM
NumberCruncher NumberCruncher is offline Get Name of Selected/Active Form Field Windows XP Get Name of Selected/Active Form Field Office 2003
Novice
Get Name of Selected/Active Form Field
 
Join Date: Jan 2014
Posts: 4
NumberCruncher is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 01-20-2014, 04:58 PM
gmaxey gmaxey is offline Get Name of Selected/Active Form Field Windows 7 32bit Get Name of Selected/Active Form Field Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,437
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

I don't think you can upload docm files here. See: https://dl.dropboxusercontent.com/u/64545773/Demo.docm
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 01-20-2014, 05:10 PM
NumberCruncher NumberCruncher is offline Get Name of Selected/Active Form Field Windows XP Get Name of Selected/Active Form Field Office 2003
Novice
Get Name of Selected/Active Form Field
 
Join Date: Jan 2014
Posts: 4
NumberCruncher is on a distinguished road
Default

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?
Reply With Quote
  #8  
Old 01-20-2014, 05:18 PM
gmaxey gmaxey is offline Get Name of Selected/Active Form Field Windows 7 32bit Get Name of Selected/Active Form Field Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,437
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

That is not the case here. Msgbox and font coloring affects the selected formfield:
https://dl.dropboxusercontent.com/u/64545773/Demo.docm
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #9  
Old 01-20-2014, 11:36 PM
fumei fumei is offline Get Name of Selected/Active Form Field Windows 7 64bit Get Name of Selected/Active Form Field Office XP
Expert
 
Join Date: Jan 2013
Posts: 440
fumei is on a distinguished road
Default

How are you adding the other formfields? Hopefully not by copying and pasting. Because that does not copy over any bookmarks.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mandatory field in a form thedeadzeds Word 1 05-09-2013 03:27 PM
Get Name of Selected/Active Form Field Form field selection allows entry into form text box David C Word 1 10-24-2012 04:53 AM
Get Name of Selected/Active Form Field Can't tab from field to field in form Lynieee Word 6 06-18-2012 02:37 PM
Get Name of Selected/Active Form Field 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:22 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft