From: Barb Reinhardt on 6 Oct 2009 13:12 I have a document that has a bunch of option buttons created with the forms toolbar. How do I access the name of the option button iand the "value" (true/false) of the option button n VBA? I have this so far and I'd like to get the OptionButton name somehow, but haven't been able to get to it. Dim myShape as InlineShape For Each myShape In myDoc.InlineShapes If myShape.OLEFormat.ProgID Like "*OptionButton*" Then 'Do something End If Next myShape Thanks, Barb Reinhardt
From: ker_01 on 6 Oct 2009 16:54 Hi Barb- Here is a code snippet I used to pull data from a template into Excel: WhichCol = 0 PasteRow = Find_Last(Sheet1) + 1 Dim ffld As Word.FormField For Each ffld In wrdDoc.FormFields WhichCol = WhichCol + 1 ConvertCol (WhichCol) Debug.Print ffld.Result Sheet1.Range(UseCol & PasteRow).Value = ffld.Result Next If you only want to pull the optionbutton data, you can modify this code for optionbuttons instead of checkboxes: tRef = "Check" & i Debug.Print wrdDoc.FormFields(tRef).CheckBox.Value If you have the ability to change the optionbutton names before they go out, it will be easier for you to reference individual fields directly, but that's up to you. HTH, Keith "Barb Reinhardt" wrote: > I have a document that has a bunch of option buttons created with the forms > toolbar. How do I access the name of the option button iand the "value" > (true/false) of the option button n VBA? > > I have this so far and I'd like to get the OptionButton name somehow, but > haven't been able to get to it. > > Dim myShape as InlineShape > > For Each myShape In myDoc.InlineShapes > > If myShape.OLEFormat.ProgID Like "*OptionButton*" Then > 'Do something > End If > Next myShape > > Thanks, > Barb Reinhardt
From: Barb Reinhardt on 6 Oct 2009 18:48 That doesn't work. Any other ideas? "ker_01" wrote: > Hi Barb- > > Here is a code snippet I used to pull data from a template into Excel: > WhichCol = 0 > PasteRow = Find_Last(Sheet1) + 1 > Dim ffld As Word.FormField > For Each ffld In wrdDoc.FormFields > WhichCol = WhichCol + 1 > ConvertCol (WhichCol) > Debug.Print ffld.Result > Sheet1.Range(UseCol & PasteRow).Value = ffld.Result > Next > > If you only want to pull the optionbutton data, you can modify this code for > optionbuttons instead of checkboxes: > tRef = "Check" & i > Debug.Print wrdDoc.FormFields(tRef).CheckBox.Value > > If you have the ability to change the optionbutton names before they go out, > it will be easier for you to reference individual fields directly, but that's > up to you. > > HTH, > Keith > > > "Barb Reinhardt" wrote: > > > I have a document that has a bunch of option buttons created with the forms > > toolbar. How do I access the name of the option button iand the "value" > > (true/false) of the option button n VBA? > > > > I have this so far and I'd like to get the OptionButton name somehow, but > > haven't been able to get to it. > > > > Dim myShape as InlineShape > > > > For Each myShape In myDoc.InlineShapes > > > > If myShape.OLEFormat.ProgID Like "*OptionButton*" Then > > 'Do something > > End If > > Next myShape > > > > Thanks, > > Barb Reinhardt
From: Graham Mayor on 7 Oct 2009 01:00 It would help to know *exactly* what has been inserted. The Forms toolbar implies a version of Word before 2007 and there is no 'options button' on that toolbar. If you have inserted a check box then the value of the checkbox is found by ActiveDocument.FormFields("Check1").CheckBox.Value where Check1 is the name of the check box field. Right click the field with the form unlocked and check properties for the field name. If you are processing forms then the following may be of help http://www.gmayor.com/ExtractDataFromForms.htm - especially the macros at the end of the page. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Barb Reinhardt wrote: > I have a document that has a bunch of option buttons created with the > forms toolbar. How do I access the name of the option button iand > the "value" (true/false) of the option button n VBA? > > I have this so far and I'd like to get the OptionButton name somehow, > but haven't been able to get to it. > > Dim myShape as InlineShape > > For Each myShape In myDoc.InlineShapes > > If myShape.OLEFormat.ProgID Like "*OptionButton*" Then > 'Do something > End If > Next myShape > > Thanks, > Barb Reinhardt
From: Barb Reinhardt on 7 Oct 2009 08:08 I believe it was added in Excel 2007 using Developer and clicking on the Legacy forms command to get to the Option Button ActiveX control. I can find no collection that contains the option buttons. They appear to be part of the InlineShapes collection, but I can't seem to define an "Option Button" object from inline shapes. I've had to work with each of them separately in VBA, with is a PITA. Does that answer your question? Barb Reinhardt "Graham Mayor" wrote: > It would help to know *exactly* what has been inserted. The Forms toolbar > implies a version of Word before 2007 and there is no 'options button' on > that toolbar. If you have inserted a check box then the value of the > checkbox is found by > > ActiveDocument.FormFields("Check1").CheckBox.Value > > where Check1 is the name of the check box field. Right click the field with > the form unlocked and check properties for the field name. > > If you are processing forms then the following may be of help > http://www.gmayor.com/ExtractDataFromForms.htm - especially the macros at > the end of the page. > > -- > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > Graham Mayor - Word MVP > > My web site www.gmayor.com > Word MVP web site http://word.mvps.org > <>>< ><<> ><<> <>>< ><<> <>>< <>><<> > > > > Barb Reinhardt wrote: > > I have a document that has a bunch of option buttons created with the > > forms toolbar. How do I access the name of the option button iand > > the "value" (true/false) of the option button n VBA? > > > > I have this so far and I'd like to get the OptionButton name somehow, > > but haven't been able to get to it. > > > > Dim myShape as InlineShape > > > > For Each myShape In myDoc.InlineShapes > > > > If myShape.OLEFormat.ProgID Like "*OptionButton*" Then > > 'Do something > > End If > > Next myShape > > > > Thanks, > > Barb Reinhardt > > >
|
Next
|
Last
Pages: 1 2 Prev: Controlling ribbon group visibility on document open Next: Extracting Footnotes and Endnotes |