[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
Re: menu click in word from VB
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 ?
1 Attachment(s)
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:
Option Explicit
Public WithEvents moApp As Word.Application
Private Sub Class_Initialize()
Set moApp = Word.Application
End Sub
Private Sub moApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = True Then
'insert your code here
'etc
'etc
MsgBox "I've stopped the BuiltIn SaveAs option"
Cancel = True
End If
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:
Option Explicit
Private Sub Document_Open()
Set gcMyEventHandler = New cAppEventHandler
End Sub
Private Sub Document_Close()
Set gcMyEventHandler = Nothing
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.
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
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
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.
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 :)
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.
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