Results 1 to 9 of 9
  1. #1
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Intercept FileSave click (Office XP W2002)

    Intercepting FileSave I have learned here before.

    But, how can I intercept the event when I click "File/Save" or clicking the button Save?

    Bjorn

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Intercept FileSave click (Office XP W2002)

    The Document_BeforeSave event should do what you want.

    If you aren't familiar with how to set up an event handler then have a look at <post#=203498>post 203498</post#> which has a good example.

    StuartR

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Intercept FileSave click (Office XP W2002)

    Thanks StuartR!

    I'll try this out in the coming week. All posts referenced to looks very interesting.


    Bjorn

  4. #4
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Intercept FileSave click (Office XP W2002)

    Thank you.

    I have tried the procedure and I got the numbers of the various control ID's in the menu.



    Using the Document_BeforeSave event I could not get working. From earlier I have a class module in which I have:
    Public WithEvents App As Word.Application
    for this proceduere:

    Private Sub App_WindowBeforeDoubleClick(ByVal Sel As Selection, Cancel As Boolean)
    ThisDocument.SpellingFlagg = True
    End Sub

    In the module ''ThisDocument'' I set:
    Private ProtectHandler As New EventClassModule


    In a Document_Open procedure, in ThisDocumjent, I have the following code:
    If ProtectHandler.App Is Nothing Then
    Register_Event_Handler
    End If


    using the following as the definition for the before-procedure:
    "Private Sub App_DocumentBeforeSave(ByVal Doc As Document,ByVal SaveAsUI As Boolean,Cancel As Boolean)"
    gives me the following error message:
    ''Procedure declaration does not match description of event or procedure having the same name''

    I do not have a procedure with the same name so it must be the first: "declaration does not match description"

    I thought I could use my existing registration of the ProtectHandler and the App declaration??


    I must be missing somthing.


    If i should get it working, how to use the control ID number in the "beforesave" event?

    Bjorn

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Intercept FileSave click (Office XP W2002)

    I don't understand the reference to Menus and control IDs, you don't need to copy the control ID stuff from the post I pointed you to, I just used this as an example of how to set up an Event handler, but you already know how to do this.

    If you have an existing Class Module that is handling Word events then you should be able to use it.

    When you edit your class module you should be able to select Document_BeforeSave from the right hand drop down menu and it will automatically create the correct declaration for you, on my Word2000 module this is exactly the same as the one you show.

    Document_BeforeSave should get called whenever Word is about to save a document. The value of SaveAsUI tells you whether it is going to display the SaveAs dialog box or just save the file, the Cancel parameter gives you an opportunity to Cancel the save.

    StuartR

  6. #6
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Intercept FileSave click (Office XP W2002)

    Hi,

    The case is that i copied the code and pasted into my .dot-file. Doing so I got the error message, but if I used the drop down list on the right side as you told me to, the error message disappeared and the Document_Before_Save-event functioned.

    Regarding the ID stuff it looks as I need to intercept(or test if it has been started or clicked) a check in macro (introduced when SharePoint is used on the system) which I found the ID number for by using the ID stuff. But I haven't been able to do so.
    I need to know whether this Check in macro is started or just the FileSave. If the Check in macro starts and if ThsDocument.Saved = True the FileSave should not start.

    Well, I may not have explained this very good, but I would like to know how I can test if a macro having a certain ID can be written.

    Thanks very much for your help so far.

    Bjorn

  7. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Intercept FileSave click (Office XP W2002)

    I hope someone else can help you here. I don't know how code in the BeforeSave event can identify where it got called from.

    StuartR

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Intercept FileSave click (Office XP W2002)

    If you want to know what the user did to invoke your event handler, you can query the CommandBars collection. See <post#=211170>post 211170</post#>.

    But if you want to know what macro(s) is(are) running, I don't think we've come up with a real answer (we have a workaround: create your own global flags). See this thread: Can a macro read the call stack? (Word 2000).

  9. #9
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Intercept FileSave click (Office XP W2002)

    Thanks to both jscher2000 and Legare Coleman.

    I've had a look at the posts. This looks very interesting. I will try tomorrow when in office. Time is about 23 here now so it is time for some rest.


    regards
    bjorn

Posting Permissions

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