|
-
Jun 11th, 2007, 04:24 PM
#1
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
|