Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jan 2001
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FileSaveAs and Read-only documents (VBA/ Word 2000 on Windows 2000)

    I have searched various newsgroups but cannot find an answer to this VBA problem.

    The scenario:
    You have a file open in Word which has the "Read-only recommended" option checked.
    If you select the "Save" button in Word's "native" (no macro) SaveAs dialog, a Word message appears saying "This file is read-only." This message includes the full path of the file in parentheses. So far so
    good.
    HOWEVER, if you replace Word's "File Save As" command with a macro (named FileSaveAs) then, if the user selects "Save" in the SaveAs Dialog, nothing happens. There does not seem to be a way to intercept
    this "Save" button in this scenario. It's only when "Cancel" is selected that error 5155 is generated.

    Has anyone found a way round this? What I want is for the same message to appear saying that the file is read-only or the ability to display my own message saying much the same thing.
    By the way, there is no problem if you change the name before selecting the "Save" button.

    Here is a code sample (Also same behaviour with dlg.Show instead of dlg.Display):

    Sub FileSaveAs()

    Dim dlg As Dialog
    Set dlg = Dialogs(wdDialogFileSaveAs)

    'Display the dialog box and exit if Cancel selected.
    If dlg.Display = 0 Then 'Cancel Button selected.
    Set dlg = Nothing
    Exit Sub
    End If

  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: FileSaveAs and Read-only documents (VBA/ Word 2000 on Windows 2000)

    I don't have a solution, but the same kind of problem occurs when automating the Templates and Add-ins dialog: if someone types the name of an nonexistent template, then clicks OK, it appears that nothing happens. Even if the user then attaches a valid template, upon closing the dialog, an error occurs.

    You could try to head this off by testing whether the document is read only and pre-loading a different file name:
    <pre>Sub FileSaveAs()
    With Dialogs(wdDialogFileSaveAs)
    If ActiveDocument.ReadOnly = True Then
    .Name = "Fred"
    End If
    If .Display = 0 Then Exit Sub
    .Execute
    End With
    End Sub</pre>


  3. #3
    New Lounger
    Join Date
    Jan 2001
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileSaveAs and Read-only documents (VBA/ Word 2000 on Windows 2000)

    Many thanks for the reply, jscher.

    I resorted to the kind of thing you suggested (testing for Read-only and then displaying a relevant message). But it's an unsatisfactory (and unsatisfying!) way to go about things. I wonder if these VBA file handling bugs have been squashed in Word 10?

    Jeremy Morton

Posting Permissions

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