Results 1 to 6 of 6
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hijack save, close, saveas? (Word97)

    How do I "hijack" Word's regular file-saving mechanism? I know it has been posted here, but the Search mechanism .....

    I have created a document for The User, and can devise a suitable name for the document.

    The user does NOT want me to save the document during the process of generation, because after I have generated the document and returned control to the user, user may decide to scrap the attempt after all.

    Consequently, although at the time I generate the letter for the user, I will know the patient's First and Last names, (and could store them as CustomDocumentProperties), I cannot use them to save the document - YET!

    At the time the user elects to do a File-Save, or a File-saveAs, or a File-Close, I want to pre-load the appropriate Word dialogue box with my proposed name, retrieved from the CustomDocumentProperties variables.


    I can see in the Document that I have access to the New, Open and Close events. There is no Save event, and if there were, I'm still not sure how to pre-empt any default name (such as "Document9") that Word might devise.

    The code below doesn't work. I think I've pasted it in only to show that I've spent some time on this (grin!); I've been using the time-of-day to generate a unique name during testing, instead of code for CustomDocumentProperties.

    <pre>Public Function FileSave()
    MsgBox "here"
    Dim strName As String
    strName = Format(Time, "HHMMSS")
    On Error GoTo fail99
    ActiveDocument.Save
    ActiveDocument.SaveAs (strName)
    fail99:
    'Sub TESTFileSave()
    ' Call FileSave
    'End Sub
    End Function
    </pre>


  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: Hijack save, close, saveas? (Word97)

    > The code below doesn't work.

    Does it not fire or does it not do what you want?

    Well, first of all, make it a Sub procedure and see if that helps.

    Next, consider that .Save on a previously unsaved document could do the wrong thing (i.e., pop up the Save As dialog), so that probably is not your best bet.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hijack save, close, saveas? (Word97)

    >Does it not fire or does it not do what you want?
    It fires, it doesn't do what I want.

    > Well, first of all, make it a Sub procedure and see if that helps.
    Done. That's my "TEST" subroutine embedded in the bottom of the function. I have one of those in almost all functions. makes it easier to re-test after a change.


    > Next, consider that .Save on a previously unsaved document could do the wrong thing (i.e., pop up the Save As dialog), so that probably is not your best bet.
    Exactly.

    <pre>Sub test()
    ActiveDocument.Save
    End Sub
    </pre>


    On a brand-new document, this will popup the saveAs dialogue with "Doc3.DOC" or similar in its teeth.

    I LIKE the idea of the saveAs dialogue popping up on a never-before-saved document, regardless of whether the user chose Save, saveAs, or Close. I'd just like to have MY name there, instead of Word's DOC3 (or whatever we are up to by now .....).



    If you were to pop that 3-liner above into Normal.Dot, then in Word choose File, New, and then run the TEST, you'd see the "Doc3.DOC" in the dialogue box.

    Can you/anyone think of a way to pre-empt the "Doc3.DOC" with something of one's own choosing, such as "FooWasHere.DOC"?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Hijack save, close, saveas? (Word97)

    > Well, first of all, make it a Sub procedure and see if that helps.
    Done. That's my "TEST" subroutine embedded in the bottom of the function.

    <big>NO!</big> Jefferson's point is that if you want to intercept a built-in command, you must write a procedure (sub) with the same name, not a function.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hijack save, close, saveas? (Word97)

    > NO! Jefferson's point is that i

    <big>OH!</big> (grin!).

    I thought that he was referring to the fact that I can't run a Function as a user. I see now what you both are trying to club into my thick skull (G&FTDR)

    I am, as you will see below, a happy camper. That simple, huh? See, without the search function I get to look, well, stupid sometimes .....

    <pre>Public Sub FileSave()
    MsgBox "in file save"
    End Sub
    Public Sub FileSaveAs()
    MsgBox "in file save AS"
    End Sub
    Public Sub FileClose()
    MsgBox "in file CLOSE"
    End Sub
    </pre>


  6. #6
    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: Hijack save, close, saveas? (Word97)

    > Can you/anyone think of a way to pre-empt the "Doc3.DOC" with something of one's own choosing

    Using the Dialogs(wd...FileSaveAs) approach often makes the most sense for that. Apologies for the roughness of this, I haven't gone digging through my many templates...

    With Dialogs(wdDialogFileSaveAs)
    .Name = "Magnum Opus.doc"
    .Show
    End With

Posting Permissions

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