Results 1 to 10 of 10

Thread: [RESOLVED] menu click in word from VB

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Resolved [RESOLVED] menu click in word from VB

    I need to detect when the "file-> save as" menu item is clicked in MsWord from VB6 ..... any ideas
    if you suggest subclassing I need some code to subclass word as I am finding it very difficult to do so .... I would appreciate it grealty if anyone has got some code to subclass if this is the only solution

    Ross

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: menu click in word from VB

    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: menu click in word from VB

    Thanks Declan

    my apologies I should have been more specific. What I want to do is when a user clicks the file save menu item I want my own dialogue box to appear instead of the msword one ....... i dont think I will be able to do that with the solution yo have given me, but thanx anyway. I think the only way I can do this is by subcalssing msword and intercepting and supressing the file save as lParam and wParam msg from the OS to word and then making my dialogue appear instead of the ususal msword dialogue ...... any further suggestions ?

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: menu click in word from VB

    In that case try this
    Add a Class model with the following, I call mine "cAppEventHandler"...
    VB Code:
    1. Option Explicit
    2.  
    3. Public WithEvents moApp As Word.Application
    4.  
    5. Private Sub Class_Initialize()
    6.     Set moApp = Word.Application
    7. End Sub
    8.  
    9. Private Sub moApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    10.    
    11.     If SaveAsUI = True Then
    12.         'insert your code here
    13.         'etc
    14.         'etc
    15.         MsgBox "I've stopped the BuiltIn SaveAs option"
    16.        
    17.         Cancel = True
    18.     End If
    19. End Sub
    NOTE: by evaluating "SaveAsUI" I only disable the SaveAs menu option and not the Save option.

    Then in an _Open Event procedure you can instantiate the object and close the object in your _Close Event proc

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Document_Open()
    4.     Set gcMyEventHandler = New cAppEventHandler
    5. End Sub
    6.  
    7. Private Sub Document_Close()
    8.     Set gcMyEventHandler = Nothing
    9. End Sub

    You will also need to Declare the gcMyEventHandler variable somewhere. I normally do this a specific module I call MGlobals where I declare all global Variables and constants.

    BTW
    under my naming convention this variable is prefixed with 'g' for Global level and 'c' for user defined class.
    in the same way my Application variable is prefixed with 'm' for Module level and 'o' for Object.

    I've attached a sample doc that shows the interception on the SaveAs event.
    Attached Files Attached Files
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: menu click in word from VB

    Man you are a life saver

    howerevr (there is always a however )
    doing it this way raises a new problem, I want it so that whenever a user clicks on the msword icon on thier desktop, to start msword, this macro has to be in that instance of word. I want it so every time they click on save as in a word doc, my dialogue will pop up. This will be as part of a vb6 executable that will be installed ... if that helps

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: menu click in word from VB

    Have a look at my posts in the attached Thread, its is about passing command line perameters to Excel, but word works just the same....

    http://www.vbforums.com/showthread.php?p=2234901
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: menu click in word from VB

    Rab
    Ignore last post, not what you need, sorry - going on 3 days without sleep.
    Dk.Brain = Null.

    Can you save your app as a word add-in (.wll file). Then in your executable regiseter the add-in and it will load evry time word is opened.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: menu click in word from VB

    jesus you are amazing , is there anything you dont know about office stuff

    I have been slugging away for bout 2 days trying to subclass word to do the same thing, and I am not even close to a solution .

    I will have to do some research on this word addin file .wll file, have not encountered those before.

    Do you have an example or example code that you, or others, have already done so that I can look at it to get the reg key, what a wll file looks like and the rest of the fine detail , so I dont have to bombard you with too many questions, in this thing up and running.

    I may be able to repay the favour one day ..... I do a lot of vb work, not much in office, with vba

    thanx again you have saved me a mountain of looking and trying different stuff

    just goes to show its not who you know its what you know

  9. #9
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: menu click in word from VB

    To create a word add-in, I use VSTO. But there are a few other methods.
    Here's a good starting point.Creating a Word Add-in

    OR if C# is more your thing...
    How To Build an Office COM Add-in by Using Visual C# .NET


    Glad I could help.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    7

    Re: [RESOLVED] menu click in word from VB

    Thanx again for helping me out saved me tons of time and effort.... if I can ever repay the favour just ask

    I had a little trouble and made a second post but another guy solved it for me

    regards

    Ross

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