简体   繁体   中英

Word VBA 'file in use' when loading dotx

I get the message 'File In Use... locked for editing by another user...' the first time I run the following sub in a Word session. After selecting 'Open a Read Only copy' the macro runs OK. The dotx file has the Read Only and Archive attributes set. Some of my users open Word sessions every few minutes (editing numerous database records one at a time in Word) and this annoys them.

Any ideas if this can be fixed?

Thanks.

    Sub Check()
    If Left(ActiveDocument.Attached Template,3) <> "RFP" Then
        With ActiveDocument
            .UpdateStylesOnOpen = True
            .AttachedTemplate = Environ("homedrive") & "\My Documents\RFP Styles.dotx"
        End With
    End If
    End Sub

I wasn't able to re-create your error (though my dotx also has the Readonly attribute checked). Perhaps your dotx has been inadvertently left open. To close any lingering copies of Windows files, go to Computer Management --> Shared Folders --> Open Files. If you see your dotx file in there, there is a button to Close it.

I experience the same problem since some months now, with no idea how to solve this. To call AttachedTemplate with.dotx files on the network path seem to trigger the readonly message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM