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

    Close invokes SaveAs (All)

    Hi

    Has anyone seen this kind of a problem before? Very unusual. Screenshot attached of the code.

    I have several documents to process so:
    read a document,
    if it is read-only,
    then close it without saving changes.
    otherwise
    process document further

    Now, for some read only documents it actually displays the 'SaveAs' dialog - for others it closes the file without any changes. I don't understand why? The documents are on the disk and set as read-only.

    I would be grateful if any body can shed some light on this. Basically, I want to open a document and close it it if read only. Unfortunately, the document has to be opened prior to checking for the properties because if it is not read-only then it is processed further.

    Thanks.

    Robie
    Attached Images Attached Images
    Thanks.
    Robie

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

    Re: Close invokes SaveAs (All)

    Do you have a Document_Close event procedure in the documents that display the Save As dialog (or in the attached template)?

    Does it help if you change the DisableAutoMacros line above the one that closes the document to

    WordBasic.DisableAutoMacros 1

  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: Close invokes SaveAs (All)

    Thanks for the quick response Hans.

    Do you have a Document_Close event procedure in the documents that display the Save As dialog (or in the attached template)? Yes - but for all documents being opened (created with same template). But I would have expected it to be consistent for all documents as they are allcreated using the same template.

    Does it help if you change the DisableAutoMacros line above the one that closes the document to

    WordBasic.DisableAutoMacros 1 (Yes - do'h. How did I miss that? <img src=/S/doh.gif border=0 alt=doh width=15 height=15> I will review the code with bit scrutiny now)

    All fixed now. It seems by changing the above line
    WordBasic.DisableAutoMacros 1 to
    WordBasic.DisableAutoMacros 0 fixed the problem. Now all read documents close without the SaveAs dialog.

    Thanks once again Hans.

    Robie
    Thanks.
    Robie

  4. #4
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Close invokes SaveAs (All)

    <P ID="edit" class=small>(Edited by wdwells on 14-Jun-07 21:12. Please note that this code came to me from the Lounge (Thanks Loungers))</P>
    <hr>Unfortunately, the document has to be opened prior to checking for the properties because if it is not read-only then it is processed further<hr>
    You can adapt the following code to determine whether or not the file is Read Only without opening it. <pre>Option Explicit

    Sub SetAttributes(filespec As String, Attrib As Long)

    Dim fs, f
    Set fs = CreateObject("Scripting.FileSystemObject")
    On Error GoTo NoFile
    Set f = fs.GetFile(filespec)
    f.Attributes = Attrib
    DoEvents
    Exit Sub
    NoFile:
    On Error GoTo 0
    Set f = Nothing
    Set fs = Nothing
    End Sub</pre>

    Regards
    Don

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

    Re: Close invokes SaveAs (All)

    1) I fail to see how setting file attributes can be used to determine whether a document is read-only.
    2) FileSystemObject looks at the document at the Windows Explorer level. It doesn't "know" about Word properties. ActiveDocument.ReadOnly can be true even if the .doc file doesn't have its Read-Only property set.

  6. #6
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Close invokes SaveAs (All)

    I had something like this in mind: <pre>Option Explicit
    Sub SetAttributes(filespec As String)

    Dim fs, f
    Set fs = CreateObject("Scripting.FileSystemObject")
    On Error GoTo NoFile
    Set f = fs.GetFile(filespec)
    If f.Attributes Mod 2 = 1 Then
    MsgBox "Read Only"
    Else
    MsgBox "NOT Read Only"
    End If
    Exit Sub
    NoFile:
    On Error GoTo 0
    Set f = Nothing
    Set fs = Nothing
    End Sub</pre>



    I failed to recognize:
    <hr>ActiveDocument.ReadOnly can be true even if the .doc file doesn't have its Read-Only property set<hr>

    Thank you for pointing this out.
    Regards
    Don

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

    Re: Close invokes SaveAs (All)

    It's rather confusing to name this procedure SetAttributes.

  8. #8
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Close invokes SaveAs (All)

    And careless of me to have posted it without reviewing it thoroughly.

    Apologies to all.
    Regards
    Don

Posting Permissions

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