Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Toggle symbols with VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
robotman - 12 Sep 2007 19:22 GMT
I'm trying to set up a roster where I can click on a symbol in front
of a person's name and it will change from an "X" to a "O".

I'm an expert at Excel VBA, but not familiar with Word VBA.

Can someone give me some ideas on how I could set up a macro to allow
the user to check on a symbol (or character) in front of a person's
name in a list and it would toggle between 2 or 3 symbols?

The list will be dynamic, so I need to write some generic code that
can identify which symbol is clicked on and toggle  it to the next
symbol.

Thanks.

John
m rafala - 12 Sep 2007 20:00 GMT
One way would be to put a CommandButton or some other control (see control
toolbox toolbar) into the document so that the caption changes with each
click.

You would need to put the following code in the document's ThisDocument
module:

Private Sub CommandButton1_Click()
   If CommandButton1.Caption = "O" Then
       CommandButton1.Caption = "X"
   Else
       CommandButton1.Caption = "O"
   End If
End Sub

> I'm trying to set up a roster where I can click on a symbol in front
> of a person's name and it will change from an "X" to a "O".
[quoted text clipped - 12 lines]
>
> John
Dave D-C - 12 Sep 2007 20:59 GMT
There's no equivalent of
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
but you could hit a menu button, leaving the cursor at your symbol:
in Thisdocument:
Option Explicit

Private Sub Document_Open()
 Dim CB As CommandBar, CBC As CommandBarControl
 Set CB = Application.CommandBars.ActiveMenuBar
 CB.Reset
 Set CBC = CB.Controls.Add(msoControlButton, , , , True)
 CBC.FaceId = 342 ' my favorite
 CBC.OnAction = "Doit"
End Sub

Private Sub Document_Close()
 Application.CommandBars.ActiveMenuBar.Reset
End Sub

Sub Doit()
 Const TblArg = "XO", TblVal = "OX"
 Dim ch$, i%
 Selection.Collapse wdCollapseStart
 ch = Chr$(Asc(Selection.Text & " "))
 i = InStr(1, TblArg, ch)
 If i > 0 Then
   Selection.Delete
   Selection.TypeText Mid$(TblVal, i, 1)
 End If
End Sub

> I'm trying to set up a roster where I can click on a symbol in front
> of a person's name and it will change from an "X" to a "O".
[quoted text clipped - 12 lines]
>
> John
Dave D-C - 12 Sep 2007 21:12 GMT
Of course, to make it "dynamic", you would want globals
TblArg$ and TblVal$
and set them to what you want, when you want.

>There's no equivalent of
>Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
[quoted text clipped - 47 lines]
>http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
>----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Shauna Kelly - 13 Sep 2007 03:58 GMT
Hi John

For a simple way to do this, that operates with a right-click, and requires
no VBA, see
How to add pop-up lists to any Word document, so you can click your way
through changes in seconds
http://word.mvps.org/FAQs/TblsFldsFms/AutoTextList.htm

For a fancier way (that operates on single-click or double-click depending
on your settings in Word) and that does require VBA, see
Enable a user to double-click text in a document to change its value
http://word.mvps.org/FAQs/MacrosVBA/AssignMacroToText.htm

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

> I'm trying to set up a roster where I can click on a symbol in front
> of a person's name and it will change from an "X" to a "O".
[quoted text clipped - 12 lines]
>
> John
robotman - 13 Sep 2007 22:26 GMT
Thanks for everyones' ideas.

Autotext seems to work well for what I'm trying to do.  Do you know if
I can set up something like Autotext but use graphics instead of text?

Under "Background Item #1" in the first link it says you can use "text
and/or graphics", but I don't see how to do the graphics with
Autotext.

Thanks.

John
Shauna Kelly - 14 Sep 2007 01:17 GMT
John

You can store any kind of content in an AutoText: images, tables, fields,
plain text, whatever. It can be one word; it can be 100 pages. Just select
the content and do Insert > AutoText > AutoText. Choose where to save it,
give it a name and you're under way.

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

> Thanks for everyones' ideas.
>
[quoted text clipped - 8 lines]
>
> John
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.