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
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 ?
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.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful
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
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