Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Process Errors on FileSave or FileSaveAs macros (WORD2003)

    Hi

    Slight (well actually a big) problem. I have a template that contains replacements for FileSave and FileSaveAs. I have encountered a problem recently that I do not know how to deal with. How do I handle errors (& so called errors) in these two macros. As follows:

    When using .Execute in FileSaveAs or ActiveDocument.Save in FileSave - it may return error 5055 (file being saved is read only) or 4198 (user wants to cancel the save because the document is being saved with track changes). The save with track changes option is set under Tools|Options|Security - 'Warn before saving, printing or sending a file that contains tracked changes or comments'. But I want to make the code generic so that it can handle any error (or so called error) in the future. My code for FileSaveAs, FileSave and HandlingtheError is as follows:

    ------------------------------------
    FileSaveAs Replacement
    Option Explicit
    Public Sub MAIN()
    Dim sDocName As String
    ProcStart:
    With Dialogs(wdDialogFileSaveAs)
    If .Display = -1 Then
    sDocName = ActiveDocument.Name ' Save filename for comparison
    PostProcess ' Update TOC etc
    On Error GoTo ErrorHandler ' If error saving the file - handle it
    .Execute ' Execute the WORD dialog to save the document
    If sDocName <> ActiveDocument.Name Then ' if document saved to a new FILENAME
    I_UpdateAllFields ' Update fields - for filename change on screen
    End If
    Else
    SendKeys "{ESC}"
    End If
    End With
    Exit Sub
    ErrorHandler:
    HandleTheError ' Function to handle the error saving file
    GoTo ProcStart ' try to save it again
    End Sub
    -------------------------------
    FileSave Replacement
    Option Explicit
    Public Sub MAIN()
    PostProcess ' Post process - update TOC etc
    On Error GoTo ErrorHandler ' If error saving the file
    ActiveDocument.Save ' Call WORD process to save the document
    Exit Sub
    ErrorHandler:
    HandleTheError ' Function to handle the error
    End Sub
    --------------------------
    Thanks.
    Robie

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

    Re: Process Errors on FileSave or FileSaveAs macros (WORD2003)

    If possible, I'd avoid hijacking the FileSave and FileSaveAs actions - as you have found, it can become really messy. You could try using the application level DocumentBeforeSave even instead. Look up WithEvents in the VBA help, and/or look at <post:=203,498>post 203,498</post:> for a description of how to work with application level events. The event handler could look like this:

    Private Sub app_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
    PostProcess
    If SaveAsUI = True Then
    I_UpdateAllFields
    End If
    End Sub

  3. #3
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Process Errors on FileSave or FileSaveAs macros (WORD2003)

    Thanks Hans.

    I apologise. I neglected to mention that this template is used for Word97 & Word 2000 only. DocumentBeforeSave etc are not available in WORD97 - that is the reason for hijacking FileSave and FileSaveAs. I guess I am stuck. [img]/forums/images/smilies/sad.gif[/img].

    The problem manifests itself in WORD2003 because of the extra option settings (& in particular by one stooooooooopid user) available only in Word2003.

    I will need to work something out somehow then. Unfortuantely, At the moment can't see a way out. Perhaps - could there be a way of not-hijacking for Word 2000/2003 and hijacking for Word97 in the same template?

    Robie
    Thanks.
    Robie

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

    Re: Process Errors on FileSave or FileSaveAs macros (WORD2003)

    > could there be a way of not-hijacking for Word 2000/2003 and hijacking for Word97 in the same template?

    Not as far as I know. I think you'd have to create two versions of the template: one for Word 97/2000 and one for Word 2002/2003 (I don't know how Word 2007 will behave).

  5. #5
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Process Errors on FileSave or FileSaveAs macros (WORD2003)

    Any other ideas anyone? I must find a suitable solution, even if it means checking for specific errors & then taking actions based on that.
    Thanks.
    Robie

  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: Process Errors on FileSave or FileSaveAs macro

    If you create the event procedures for more modern versions, what happens in old version? Do they generate errors or simply not run?

    If there are no errors, you could include both and branch to default behavior in your FileSave and FileSaveAs procedures based on Word version (might be Application.Version, but I haven't looked it up to confirm).

Posting Permissions

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