Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 39

Thread: Solved: Document_Save Event Handler

  1. #1

    Solved: Document_Save Event Handler

    Is there anyway to have a sub procedure that is triggered by saving an MS Word document? Thanks!

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    In a standard module:
    [VBA]Sub FileSave()
    MsgBox "Your message Here."
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Quote Originally Posted by lucas
    In a standard module:
    [vba]Sub FileSave()
    MsgBox "Your message Here."
    End Sub[/vba]
    Thanks a lot lucas! That's great, is there any way I can stop it appearing in the macro box? Because:

    [VBA]Option Private Module[/VBA]

    doesn't work?

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Not that I am aware of....I tried several things including adding it to thisdocument to no avail. Maybe Gerry or one of the regular Word guys will have an idea.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Quote Originally Posted by lucas
    Not that I am aware of....I tried several things including adding it to thisdocument to no avail. Maybe Gerry or one of the regular Word guys will have an idea.
    Okay, thanks a lot for your help lucas! I'll leave this thread open a while and see if anyone replies!

  6. #6
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    The Word.Application object exposes a DocumentBeforeSave event
    that you could use. You will need to implement a class to get at it,
    though.

    Go to the VB Editor, and in the help search on Application Events for
    an article on how to expose those events in VBA.
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

  7. #7
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Or, you could also disable getting the macros dialog box.

    Sub ToolsMacro()
    ' do nothing
    ' disables Tools > Macro > macros
    ' AND Alt-F8
    End Sub

  8. #8
    Thanks guys! I've ended up with a template! However, when I try to use it as a template I find that the macros don't seem to work! That is when I open it I still get the enable macro's warning, but the combo boxes aren't being populated! What is the problem?

  9. #9
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    As this has nothing to do with what you started the thread with, how are we to really know? Youy never mentioned it. A good place to start is to post what your code is to populate. Also, be specific with terms like "open" and "use".

    Does that mean, specifically, you cloned a new document with File > New (the way to "use" templates) and when the new document is "opened" the combobox does not populate?

    None of which has anything to do with saving the file - the topic you posted for the thread.

  10. #10
    Quote Originally Posted by fumei
    Does that mean, specifically, you cloned a new document with File > New (the way to "use" templates) and when the new document is "opened" the combobox does not populate?
    That is what I mean. Any ideas why that is?

    Quote Originally Posted by fumei
    None of which has anything to do with saving the file - the topic you posted for the thread.
    I know! I just thought I'd tag it on the end in case anyone had any ideas instead of starting I new thread. But I'm happy to start a new thread if that would be better!

  11. #11
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    No, as you did not bother to post any code. Nope sorry....haven't a clue. It is hard to have idea when I have NO idea what you are currently doing.

  12. #12
    Quote Originally Posted by fumei
    No, as you did not bother to post any code. Nope sorry....haven't a clue. It is hard to have idea when I have NO idea what you are currently doing.
    Okay I've attached a document which was based on the template. Can you see what the problem may be now?

  13. #13
    Quote Originally Posted by icthus123
    Okay I've attached a document which was based on the template. Can you see what the problem may be now?
    Okay that didn't work! Here it is again!!

  14. #14
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    you need to post the pprTemplate.dot

    There is no code in the doc file you posted.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  15. #15
    Quote Originally Posted by lucas
    you need to post the pprTemplate.dot

    There is no code in the doc file you posted.
    I tried to post that but this website won't upload .dot files for some reason! but I think the code is there under Project (PPRTemplate) > Microsoft Word Objects > ThisDocument, or it is when I open the link anyway!

  16. #16
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    No code in the document you posted. Try zipping the .dot file and post it.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  17. #17
    Quote Originally Posted by lucas
    No code in the document you posted. Try zipping the .dot file and post it.
    Okay, here it is!! I don't know why I didn't think of that!

  18. #18
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I find comboboxes referenced but I don't see them...
    [VBA]cboNIC.AddItem arrAll[/VBA]
    no comboboxes in the files you have posted.

    Question: Are you trying to populate specific places in the sheet using document properties? Why not use bookmarks?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  19. #19
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I have to leave for a while so be patient. I also see no userform in either of the documents you posted.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  20. #20
    Quote Originally Posted by lucas
    I have to leave for a while so be patient. I also see no userform in either of the documents you posted.
    okay thanks, there isn't any userform. The combo boxes are on the page and the borders are hid. The combo boxes are on the first page where it says no.

Posting Permissions

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