PDA

View Full Version : Word Documents are staying "Locked"



GRCNC
10-31-2016, 10:32 AM
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

gmaxey
10-31-2016, 01:33 PM
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.

GRCNC
11-01-2016, 09:26 AM
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

McCrayS
11-25-2016, 10:19 AM
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