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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » FileSaveAs and Read-only documents (VBA/ Word 2000 on Windows 2000)

    Author
    Topic
    #363866

    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

    Viewing 0 reply threads
    Author
    Replies
    • #557389

      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:

      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
      • #557421

        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

    Viewing 0 reply threads
    Reply To: FileSaveAs and Read-only documents (VBA/ Word 2000 on Windows 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: