Compile Error Named Argument Not Found Word 2007

J

Jules

I am trying to create NewDoc using encrypted WorkGroupTemplates - below code
works for Word documents not encrypted.

***Code between asterisks courtesy of Greg Maxey

Sub NewDoc(pName As String)
Documents.Add Template:=Path & pName
End Sub
Function Path() As String
Path = Application.Options.DefaultFilePath(wdWorkGroupTemplatesPath)
Path = Path & "\"
End Function
***

I am trying to alter code below - but in line 3 the word "Template" is
highlighted Named Argument Error (Break Mode)
Any suggestions on how to make this work with encrypted (password) files
please? It's way over my skill level without help.

1 Public Sub NewDoc(pName As String) 'Because it says NewDoc is that a
problem?

2 Dim Temp As Document

3 Set Temp = Documents.Open(Template:=Path & pName,
PasswordDocument:="1234", Visible:=False)

Documents.Add Template:=Path & pName

Temp.Close

End Sub

Function Path() As String
Path = Application.Options.DefaultFilePath(wdWorkgroupTemplatesPath)

Path = Path & "\"
End Function

Many thanks.
 
J

Jonathan West

I suspect that "Path" is used elsewhere for something - it is certainly a
named item in the Word object model. Change your function to something like
TemplatesPath and see if the problem goes away
 
S

StevenM

To: Jules,

I've never worked with encrypted documents and/or templates, so I'm not
going to be much help to you on that. But as for:

Set Temp = Documents.Open(Template:=Path & pName, PasswordDocument:="1234",
Visible:=False)

One creates a new document based on a template, but one opens an existing
document (even if that be a template) based on a file name. Thus you need:
FileName:= rather than Template:=

Steven Craig Miller
 
J

Jules

StevenM/TonyJ/JonathanW

Staring me in the face really THANK YOU Steven (and Tony). One thing I've
learned is to step away from a project when I can't see the ridiculously
obvious.

Works like a charm (Tony had already told me to use "FileName") but this is
different code and is for the Ribbon dropdown menu.

Two ribbon dropdown menus down and one more to go. Thank you all for help
with using encryption on templates.
 
J

Jules

One more question please if I may!

With filename Open if you have Windows in Taskbar (which is to be used) the
template on opening a new document and running its autotexec macro is not
the activedocument screen - is there any code to force the new document to
be the active document screen without too much effort?
 
T

Tony Jollans

Hi Jules,

You need to be a bit more precise with terminology - "opening a new
document" is slightly confusing :(

When you open the template, it is not the active document because
visible:=false is specified. But, its autoExec macro, if it has one, won't
be running anyway.

When you create a new document, it should be the active document - but if it
isn't you can always take a reference when creating it by coding:

Set mydoc = documents.add(.....

However, again, its AutoExec macro, if it has one, still won't be running.
 
J

Jules

Thank you Tony, let's hope I've mastered FileNew FileName and so forth now!

Thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top