|
-
Jun 10th, 2007, 09:13 PM
#1
Thread Starter
New Member
Toggling - Can You Do It?
Developing medical records application using MS Office 2002:
Looking for suggestions for how to toggle a "(-) " to a "(+) " and back again using a double left mouse click while pointing to the "(-) " or "(+) " in a Word document.
(-) = open parenthesis,minus,closed parenthesis,space
Please keep instructions very simple, I am not a developer.
Thank you!
-
Jun 11th, 2007, 11:34 AM
#2
Re: Toggling - Can You Do It?
There's no simple way to do it.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jun 11th, 2007, 11:46 AM
#3
Re: Toggling - Can You Do It?
Moved to Office Development
What are you using: Excel VBA? Access VBA? Word VBA? Something else VBA?
-
Jun 11th, 2007, 02:22 PM
#4
Re: Toggling - Can You Do It?
What is it you are trying to "toggle"?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 11th, 2007, 04:24 PM
#5
Re: Toggling - Can You Do It?
OK, there is a way to do it. You need to paste the following into the General Declarations bit of your VBA editor:
Code:
Public WithEvents appWord As Word.Application
Private Sub Document_Open()
Set appWord = Application.Application
End Sub
Private Sub appWord_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel As Boolean)
If Sel.Words(1) = "(+) " Then
MsgBox "Selected (+) "
End If
End Sub
What are we doing here?
We are declaring appWord as a Word Application, and using WithEvents to access all the events of that Word application, which are not normally visible through code. When the document opens, we are setting the variable appWord to be the current Word application. Then, we are trapping the BeforeDoubleClick event to intercept the double-clicking and, if the currently selected word is "(+) " then we do some action. Note that we use the Sel selection that is passed, but beware that the double click actually changes the selection to a single insertion point during the double click, and then puts it back afterwards. Hence we can't check to see what the full current selection is, because it is just a character. We need to check the word that the insertion point is in, and if it is the desired one then we do something.
Drawbacks: The variable appWord is only set when you open the document. If you start interfering with the VBA code by stopping it, you will reset the value of this variable to Null, and hence things will stop working until you re-open the file. You may wish to stick a button in temporarily to reassign this value (i.e. to click it whenever you tinker with the code, so as to get it going again). However, I have included it in this format so that you can see how it works.
Paste this in, try to figure out how it works, and then post back with more questions.
zaza
Last edited by zaza; Jun 11th, 2007 at 04:31 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|