Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documents.Add results in template being locked

Tags:

ms-word

vba

I have a macro that creates a new document based on a template stored on a network share. This macro is stored in each user's Word\STARTUP folder as the file "macros.dotm" and is executed by a button added to a toolbar.

The template file gets locked as soon as the macro code is executed and stays locked so long as the derivative document is still open by another user.

It has no impact on their ability to open new documents based on the macro, but if I want to edit the template, I have to ask them to close Word (and hope nobody else goes into it).

Macro code:

Documents.Add Template:="F:\templates\letterhead.dotm", NewTemplate:=False, DocumentType:=0`
like image 968
gravyface Avatar asked Jul 26 '10 13:07

gravyface


1 Answers

One way around this is detaching the document from the template after it is generated:

Dim doc As Document
Set doc = Documents.Add(Template:="F:\templates\letterhead.dotm", NewTemplate:=False, DocumentType:=0)
Set doc.AttachedTemplate = Nothing

Alternatively, change the filesystem permissions on the template so only you have write access.

like image 197
Foole Avatar answered Sep 25 '22 15:09

Foole