Results 1 to 11 of 11
  1. #1
    Star Lounger
    Join Date
    Apr 2002
    Location
    Sydney Australia, New South Wales, Australia
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Application Events (Word 2000)

    Does anyone know how to create an event handeler which once run will activate a macro when the user selects save in the save as built in dialog.
    I also need to read the path the user has selected.
    In our system we have Record directories which have been set-up write only.
    The idea is that if they select a path in the system with the word Record in it the file name will be tagged with the date and hour saved prior to saving.
    This will allow them to keep several versions of the same filename as true records which cannot be altered.

  2. #2
    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: Application Events (Word 2000)

    I don't know how to do it as an event handler, but you can replace the native FileSaveAs command with a macro like this:

    <pre>Sub FileSaveAs()
    With Dialogs(wdDialogFileSaveAs)
    If .Display Then
    If InStr(1, Options.DefaultFilePath(wdCurrentFolderPath), _
    "record", vbTextCompare) Then
    .Name = Left(.Name, InStrRev(.Name, ".") - 1) & _
    Format(Now, " yyyy-mm-dd-hh-nn-ss") & _
    Right(.Name, Len(.Name) - InStrRev(.Name, ".") + 1)
    End If
    .Execute
    End If
    End With
    End Sub</pre>

    I wish I had time tonight to comment this a bit. Basically it checks the path the user chose and tries to insert a formatted date/time string between the file name and extension entered by the user. Please post any questions not answered by the online help.

    Note to Word 97 users: InStrRev was added in VBA 6 (Office 2000), sorry.

  3. #3
    Star Lounger
    Join Date
    Apr 2002
    Location
    Sydney Australia, New South Wales, Australia
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application Events (Word 2000)

    Thanks for the suggestion
    but I don't want to replace any native code
    even if I did want to I don't know how ?

    Since posting the original I have had another thought and have tried an add in to add a comand to the File Menu I have called "Save As Record"
    But I now need a way to write to the Save As Dialog / File Name Box this would be a simple solution,
    or I could create my own dialog that looks like the save as one a bit tedious.

    Got any ideas

  4. #4
    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: Application Events (Word 2000)

    Wasn't I supposed to log off and get some sleep??

    Anyway, to "replace" (really, override) a Word command, you simply need to create a macro in the Normal template, or the document template, or any global template, with a name identical to the name of the Word command. So the above macro would step in automagically when you choose Save As... from the File menu. If you try it, I think you'll find this the most direct route to solve the problem. However, if you want to actually interact with the Save As dialog, a separate macro might be better, since the replacement macro runs every time the user runs a Save As, and it might be too much overhead.

  5. #5
    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: Application Events (Word 2000)

    > I now need a way to write to the Save As Dialog / File Name Box

    Ralph, can you explain the sequence of events in your code? Originally, I gave you a macro that let the user choose a name and then it took that and tacked on the date and time before saving. This was done invisibly, after the user closed the dialog. What do you want to happen now? Do you want the date to be tacked on when the user sees the dialog? If so, you can edit the .Name property before popping up the dialog, like this:

    <pre>Sub FileSaveAs2()
    With Dialogs(wdDialogFileSaveAs)
    If InStr(1, Options.DefaultFilePath(wdCurrentFolderPath), _
    "record", vbTextCompare) Then
    .Name = Left(.Name, InStrRev(.Name, ".") - 1) & _
    Format(Now, " yyyy-mm-dd-hh-nn-ss") & _
    Right(.Name, Len(.Name) - InStrRev(.Name, ".") + 1)
    End If
    .Show
    End With
    End Sub</pre>

    The initial part of this file name is pretty useless, so this probably isn't exactly what you're after, but I need more information.

  6. #6
    Star Lounger
    Join Date
    Apr 2002
    Location
    Sydney Australia, New South Wales, Australia
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application Events (Word 2000)

    Tried Your Code but it doesn't work the way you might expect.
    It's sorta catch 22
    The user selects the folder and only then will the macro be able to check if "Record" is in the path but by then the macro is waiting for the dialog to complete.

    A simple solution is to remove the If, then call the code from an add in called Save As Record which I have put in "File" just under Save As.
    This seems to work OK but I would realy like to trap the Save event and strip the date if the user has not selected a Record Folder.

    Thanks

    Ralph

  7. #7
    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: Application Events (Word 2000)

    That's why it wrote it the other way the first time. <img src=/S/wink.gif border=0 alt=wink width=15 height=15> Was there a crucial feature missing from the first version that I might be able to add?

  8. #8
    Star Lounger
    Join Date
    Apr 2002
    Location
    Sydney Australia, New South Wales, Australia
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application Events (Word 2000)

    I don't know why but the first version didn't seem to work for me.
    The second version works fine with the add in.
    Thanks
    But Now I realy need to be able to trap when the user selects "save" in the save as dialog, then
    if they have not selected a path with "Record" in it, strip the date off before saving.
    if they have selected a path with "Record" in it save as is.

    If Word had a before save event things would be a lot simpler. MS Grrrrrrr #@!!!

  9. #9
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Application Events (Word 2000)

    Ralph,

    Word (2000 or later) does provide an application-level DocumentBeforeSave event. I think there has been code posted here in the past relating to setting up an application-level event handler; sorry don't have time to track it down right now.

    For a start, have a look at the Word VBA help topics 'Using Events with the Application Object' and 'DocumentBeforeSave Event'.

    Gary

  10. #10
    Star Lounger
    Join Date
    Apr 2002
    Location
    Sydney Australia, New South Wales, Australia
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application Events (Word 2000)

    Thanks

    Another way around my problem is to deliberatly put an illegal character in the file name then trap the error
    Very messey but it might work.

    Thanks again for the Help

    Ralph

  11. #11
    Star Lounger
    Join Date
    Apr 2002
    Location
    Sydney Australia, New South Wales, Australia
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application Events (Word 2000)

    Thanks

    Another way around my problem is to deliberatly put an illegal character in the file name then trap the error
    Very bad practice but it might work.

    Thanks again for the Help

    Ralph

Posting Permissions

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