Consulting

Results 1 to 4 of 4

Thread: Word Documents are staying "Locked"

  1. #1
    VBAX Regular
    Joined
    Aug 2016
    Posts
    11
    Location

    Word Documents are staying "Locked"

    Hi -

    I'm relatively new to Word VBA. Helping a co-worker w/ a project. She has several documents that are locked for editing. When I open the file(s), they are definitely locked for editing.

    I have a macro that opens up several of the files (these files are stored on SharePoint) and copies them all into 1 new file. Everything is working as I would like EXCEPT when I use my newly created file (with the 5-7 locked documents combined), all of the files are now editable. I can delete anything and everything - which is not what we want.

    My code is relatively long, but here is what I'm using to copy over the locked files:

    Dim docProposal As String
    docProposal = ActiveDocument.Name
    
    Dim strPath As String
    Dim oRng As Range
     
    Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0
    
    
    'Opens the 1st file and inserts the entire document at the current selection
    Selection.InsertFile FileName:=strPath & "HEN%20File%20Creator/File%20Intro.docx"
    Selection.InsertParagraphAfter
    Selection.InsertBreak Type:=wdSectionBreakNextPage
    Selection.Collapse direction:=wdCollapseEnd
    Wondering if there should be anything else added to maintain the 'locked' status?

    Thanks,

    GRC

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,354
    Location
    You would need to add protection i.e., No Changes - Read Only" to the document and then create editable regions if you need to edit only parts of the file.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Regular
    Joined
    Aug 2016
    Posts
    11
    Location

    That Worked, thanks!

    Quote Originally Posted by gmaxey View Post
    You would need to add protection i.e., No Changes - Read Only" to the document and then create editable regions if you need to edit only parts of the file.
    Here is what I put in my code before the "Unload Me".

    thanks Greg!

    ActiveDocument.Protect Password:="pw1234", NoReset:=False, Type:=wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False

  4. #4
    This behaviour may occur if Word determines that the owner file for the document already exists. This may occur if one or more of the following conditions are true:

    • Word previously quit improperly and, therefore, did not delete the owner file. -or-
    • A second instance of Word is running in the background with the document already open. -or-
    • The document is shared over a network, and another user has it open. From my personal experience, I've found a combination of the first and third point above can recreate this error quite constantly

Posting Permissions

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