Option button

J

Jeffery B Paarsa

In a form I have a couple of Option button that are grouped so the selection
between these to button is exclusive. I would like to transfer Values of
these buttons "True, False" whatever it is to a similar Option button on a
Word Document. Option buttons on the Word document have bookmark id for each
button. How can I transfer the Values of the Option button from the UserForm
to the Document? Any suggestions?
 
H

Helmut Weber

Hi Jeffery,

to me this seems to be pretty complicated,
but certainly doable.
Don't expect a ready to use solution.

I'dont think you need bookmarks at all.

Ok, I got a userform with two grouped checkboxes,
and two checkboxes in my document. So:

Private Sub CommandButton1_Click()
Dim oInl As InlineShape

If Me.OptionButton1.Value = True Then
For Each oInl In ActiveDocument.InlineShapes
If oInl.OLEFormat.ClassType = "Forms.OptionButton.1" Then
'MsgBox oInl.OLEFormat.Object.Name
If oInl.OLEFormat.Object.Name = "OptionButton1" Then
oInl.OLEFormat.Object.Value = True
Exit Sub
End If
End If
Next
End If

If Me.OptionButton2.Value = True Then
For Each oInl In ActiveDocument.InlineShapes
If oInl.OLEFormat.ClassType = "Forms.OptionButton.1" Then
If oInl.OLEFormat.Object.Name = "OptionButton2" Then
oInl.OLEFormat.Object.Value = True
Exit Sub
End If
End If
Next
End If
End Sub

Which could be improved in many ways.
It's only to demonstrate the possibility.
Not to speak of triple state option buttons.

With lots of options buttons on the userform grouped together,
I'd recommend to put them into an array,
which unlike in VB, is possible only at runtime in VBA.

Google for my decent name and "array of controls".

I think it should be possible as well,
to create an array of oleformat.objects,
or an array of oleformat.objects of classtype "Forms.OptionButton.1".

Though some well known names here, probably with good reason,
warn before using too many OLEformat.objects.

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
P

Playing WMA files in squence

My friend thank you for the info. but I was able to resolve my problem lot
easier that I thought... These two lines will set the option button values
irregardless of being True or False.
ActiveDocument.SHairLossR = UserForm1.BtnSHairLossR.Value
ActiveDocument.SHairLossP = UserForm1.BtnSHairLossP.Value
Both Option button are grouped under the group name of HairLoss.

Warmest Hello from Southern Calif. Los Angles Orange County.

Jeff Paarsa....
 
J

Jeffery B Paarsa

My friend thank you for the info. but I was able to resolve my problem lot
easier that I thought... These two lines will set the option button values
irregardless of being True or False.
ActiveDocument.SHairLossR = UserForm1.BtnSHairLossR.Value
ActiveDocument.SHairLossP = UserForm1.BtnSHairLossP.Value
Both Option button are grouped under the group name of HairLoss.

Warmest Hello from Southern Calif. Los Angles Orange County.

Jeff Paarsa....
 
J

Jeffery B Paarsa

My friend thank you for the info. but I was able to resolve my problem lot
easier that I thought... These two lines will set the option button values
irregardless of being True or False.
ActiveDocument.SHairLossR = UserForm1.BtnSHairLossR.Value
ActiveDocument.SHairLossP = UserForm1.BtnSHairLossP.Value
Both Option button are grouped under the group name of HairLoss.

Warmest Hello from Southern Calif. Los Angles Orange County.

Jeff Paarsa....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top