Results 1 to 5 of 5

Thread: Toggling - Can You Do It?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    1

    Question 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!

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Toggling - Can You Do It?

    Moved to Office Development

    What are you using: Excel VBA? Access VBA? Word VBA? Something else VBA?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    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.
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width