Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-25-2016, 03:37 AM
ramkumar.yoganathan ramkumar.yoganathan is offline How to get the MS Word Form Fields Check box associated text and their value using VBA? Windows 7 64bit How to get the MS Word Form Fields Check box associated text and their value using VBA? Office 2013
Novice
How to get the MS Word Form Fields Check box associated text and their value using VBA?
 
Join Date: Nov 2016
Posts: 1
ramkumar.yoganathan is on a distinguished road
Default How to get the MS Word Form Fields Check box associated text and their value using VBA?

How to get the MS word document checkbox form element associated text value. I am able to extract the value of the checkbox. I tried with bookmark and name properties and found that there is no value associated with bookmark filed of the checkbox. I got the following output. Any thoughts?

Sub Test()
Dim strCheckBoxName As String
Dim strCheckBoxValue As String
For i = 1 To ActiveDocument.FormFields.Count
If ActiveDocument.FormFields(i).CheckBox Then
strCheckBoxName = ActiveDocument.FormFields(i).Name
strCheckBoxValue = ActiveDocument.FormFields(i).CheckBox.Value
Debug.Print strCheckBoxName & " = " & strCheckBoxValue
End If
Next
End Sub

Output:



Check1 = True
Check1 = True
Check1 = True
Check1 = False
Check1 = False
Check1 = False

Solution looking for:

A = True
B = True
C = True
D = False
E = False
F = False

Thanks for your help.
Attached Images
File Type: png form_field.PNG (1.4 KB, 18 views)
Reply With Quote
  #2  
Old 11-25-2016, 04:59 AM
gmayor's Avatar
gmayor gmayor is offline How to get the MS Word Form Fields Check box associated text and their value using VBA? Windows 10 How to get the MS Word Form Fields Check box associated text and their value using VBA? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

What you require is as follows. The names will depend on what you have called the check boxes. The default is Checkn where n is an incrementing number

Code:
Sub Test()
'Graham Mayor - http://www.gmayor.com - Last updated - 25/11/2016 
Dim oFF As FormField
Dim strCheckBoxName As String
Dim strCheckBoxValue As String
Dim i As Long
    For i = 1 To ActiveDocument.FormFields.Count
        Set oFF = ActiveDocument.FormFields(i)
        If oFF.Type = wdFieldFormCheckBox Then
            strCheckBoxName = oFF.Name
            strCheckBoxValue = oFF.CheckBox.Value
Debug.Print strCheckBoxName & " = " & strCheckBoxValue
        End If
    Next
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to keep formatted form fields after mail merge or replace text with formatted form fields jer85 Word VBA 2 04-05-2015 10:00 PM
Entering HELP Text for Word 2010 form fields slandi Word 0 03-28-2014 08:09 AM
Duplicating form fields (check-boxes) Jānis Word 3 09-16-2012 12:09 PM
How to get the MS Word Form Fields Check box associated text and their value using VBA? Cannot enter text into form fields, Word 2007 mjr55 Word 7 04-19-2012 04:24 PM
How to get the MS Word Form Fields Check box associated text and their value using VBA? Form Fields - Create blank form text field with if statement? LAssist2011 Word 5 12-14-2011 03:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:01 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