"Is/ Is not" toggle

D

Dylan

Is it possible to have a text field "Is/ Is not" on a document where one of
them is always struckthrough and the user can click on the field to toggle
between "Is" and "Is not"?

Regards
D Dawson
 
T

Tony Jollans

Charles Kenyon is an MVP? I didn't know that, and I haven't seen him around
for a year or two.
 
D

Doug Robbins - Word MVP

Once an MVP, always an MVP.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Dylan

Hi Doug

Using Charles' info and Bill Coan's info at:
http://word.mvps.org/faqs/macrosvba/AssignMacroToText.htm,
I've created a macrobutton which toggles the textstrings. But I'm stuck at
formatting the font, in order to strikethrough one of the options. Can you
please help?

Here's the code I'm working with;
(Note that lines 12-15 are the lines I've added in an attempt to format the
text string") I've also carried out a search to find a solution to formatting
the font of a defined textstring, in the the other newsgroups, but haven't
come up with anything.

Sub TextCarousel()
Dim str1 As String, str2 As String, str3 As String, str4 As String
str1 = "Yes"
str2 = "No"
str3 = "Yes"
str4 = "No"

Select Case Mid(Selection.Fields(1).Code.Text, 26)
Case str1
Selection.Fields(1).Code.Text = _
"macrobutton TextCarousel " & str1 & str2
str2.Select
With Selection.Font
.StrikeThrough = True
End With
Case str2
Selection.Fields(1).Code.Text = _
"macrobutton TextCarousel " & str3 & str4
str3.Select
With Selection.Font
.StrikeThrough = True
End With
Case Else
Selection.Fields(1).Code.Text = _
"macrobutton TextCarousel " & str3
End Select
End Sub
 
D

Doug Robbins - Word MVP

Set up the MacroButton in the document with

{ MACROBUTTON SymbolCarousel No/}

And immediately after the closing } type

YesNo

Select the Yes and from the Insert menu select Bookmarks and enter the
bookmark name Yes. Then select the No of YesNo and create a bookmark for it
with the name of No. To select those words individually, you may have to
uncheck the "When selecting, automatically select entire word" under
Tools>Options>Edit.

Select the word Yes and format the font as Strikethrough. Select the word
No and format it as Strikethrough and Hidden.

Then use the following code:

Sub SymbolCarousel()

Dim Str1 as String, Str2 As String

Str1 = "Yes/"
Str2 = "No/"

Select Case (Mid(Selection.Fields(1).Code.Text, 29)
Case Str1
Selection.Fields(1).Code.Text = " MACROBUTTON SymbolCarousel " &
Str2
With ActiveDocument
.Bookmarks("No").Range.Font.Hidden = True
.Bookmarks("Yes").Range.Font.Hidden = False
End With
Case Str2
Selection.Fields(1).Code.Text = " MACROBUTTON SymbolCarousel " &
Str1
With ActiveDocument
.Bookmarks("No").Range.Font.Hidden = False
.Bookmarks("Yes").Range.Font.Hidden = True
End With
End Select

End Sub



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Dylan

Hi Doug!

I tried fiddling with it - trying to move the "Yes" bookmark on front of the
{}Field, but it doesn't work.

It would be good to have it so that it always says Yes/No rather than toggle
between yes/No and No/Yes.

Thanks for helping.
Dylan
 
D

Doug Robbins - Word MVP

Using the following code and with the bookmark Yes before the field and
containing a struck through Yes and the bookmark No after the field and
containing the struck through No, it works as desired. But note that the
position of the macro button changes so that it is necessary to double click
on the text that is not struck out to get it to work. You must of course
start with one of the strings in the MacroButton field. That is either a
Yes/ or a /No.

Dim Str1 As String, Str2 As String

Str1 = "Yes/"
Str2 = "/No"
Select Case Mid(Selection.Paragraphs(1).Range.Fields(1).Code.Text, 29)
Case Str2
Selection.Paragraphs(1).Range.Fields(1).Code.Text = " MACROBUTTON
SymbolCarousel " & Str1
With ActiveDocument
.Bookmarks("No").Range.Font.Hidden = False
.Bookmarks("Yes").Range.Font.Hidden = True
End With
Case Str1
Selection.Paragraphs(1).Range.Fields(1).Code.Text = " MACROBUTTON
SymbolCarousel " & Str2
With ActiveDocument
.Bookmarks("No").Range.Font.Hidden = True
.Bookmarks("Yes").Range.Font.Hidden = False
End With
End Select


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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