views:

35

answers:

2

I have a simple macro that creates a new document based on a template that's 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 their toolbar.

The problem I have is that the template file gets locked as soon as the macro code (see below) 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

+3  A: 

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.

Foole
awesome, thanks man.
gravyface
Hate to take it away, but I'm getting a syntax error on `Set doc.AttachedTemplate = Nothing` stating, "Run-time error '5946': 'Name' is not a by reference property."
gravyface
Ok, I was able to get it to work by changing `doc.AttachedTemplate = ""`, which a MsgBox confirms it defaults it back to Normal.dotm. However, the template is still locked, so this method doesn't work.
gravyface
Oops I should test the code before I post it. I am surprised it doesn't release the lock with your version.
Foole
+2  A: 

The issue is that the template is on a network drive - this is a pretty common issue. One way to get around it is to have your calling template copy over that template locally first and then create a new doc based off of that (and then delete the template when done).

Mahin