PDA

View Full Version : Chose Option Button based on text



Anto_bt
03-10-2015, 08:26 AM
I have text in word and 2 Option Buttons.

I want when there writes "Black" to be chosen OptionButton1 when it is writing "White" to be chosen OptionButton2.

Thank you!

gmaxey
03-10-2015, 02:57 PM
You are going to have to try a lot harder to define your situation and requirements before anyone here will have a hope to answer.

Anto_bt
03-11-2015, 01:25 AM
12986

Here is file, so I want when is White to be like this, and when is black to be checked other Option field.

Thank you!

gmayor
03-11-2015, 02:29 AM
The problem with your question is that there is nothing to automatically trigger the option button selection by typing the text. It is easy enough to check the box and set the text, but the other way is problematical. The nearest you can get that I can think of, is to insert a text content control in place of the text. Title the content control 'ColourText' then in the ThisDocument module of the document insert the following code. Save the document as macro enabled or the macro will be lost.

Type 'white' or 'black' (not case sensitive) in the content control and click anywhere outside it (the macro fires on exit from the control). The appropriate option button will be selected. Type anything else and you will see a message box warning.



Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim oCC As ContentControl
For Each oCC In ActiveDocument.ContentControls
If oCC.Title = "ColourText" Then
If InStr(1, LCase(oCC.Range.Text), "white") > 0 Then
Me.OptionButton1.Value = True
Me.OptionButton2.Value = False
ElseIf InStr(1, LCase(oCC.Range.Text), "black") > 0 Then
Me.OptionButton1.Value = False
Me.OptionButton2.Value = True
Else
MsgBox "Enter 'White' or 'Black' only"
oCC.Range.Select
oCC.Range.Text = ""
oCC.Range.Collapse 0
Exit For
End If
End If
Next oCC
lbl_Exit:
Exit Sub
End Sub

Anto_bt
03-12-2015, 04:06 AM
It is function great, but do you know how can i input data in dropdown directly from excel. Because before was maded in Mailings.

Thank you