Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to fill-in docproperties before editing a sjabloon 1

Status
Not open for further replies.

holle400

Programmer
Dec 17, 2003
16
0
0
NL
Hi all,

I have to restyle the sjabloons used by our department and I want them to use some non-standard docproperties in MsWord by default.

So if they pick a sjabloon, they first have to fill-in these properties like 'reference' and titel, before they can make the document.

Does anyone have an idee?

Thnx in advance
Ewald
 
Hi Ewald,

Prompting for them in the Document_New Event in the Template seems about the easiest. Something like
Code:
Titel = InputBox("Titel?")
On Error Resume Next
ActiveDocument.CustomDocumentProperties("Titel").Value = Titel
If Err.Number <> 0 Then _
    ActiveDocument.CustomDocumentProperties.Add Name:="Titel", _
                                                LinkToContent:=False, _
                                                Value:=Titel, _
                                                Type:=msoPropertyTypeString

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Hi Tony,

Thnx for the code. It works great. How do I get it started from using the template to create a new document. Do I have to make a new class or object?
I'm new to VB(A), so I hope the questions are'nt that stupid.

@StuckInTheMiddle
Sorry for the incorrect word. Sjabloon is dutch for template.

Greetings,
Ewald
 
Hi Ewald,

[ul][li]Edit the template.[/li]
[li]Go to the VBE (Alt+F11)[/li]
[li]If you don't see the project explorer press Ctrl+r[/li]
[li]Find the entry for your template - (TemplateProject(YourTemplateName) (misschien is het anders in het Nederlands) and expand it[/li]
[li]Underneath it you will see Microsoft Word Objects[/li]
[li]Underneath that you will see ThisDocument[/li]
[li]Double click on ThisDocument[/li]
[li]At the top of the main window there are two dropdowns. From the left hand one, select Document[/li]
[li]From the right hand dropdown, select New - it should default to this anyway[/li]
[li]Add the code in the Document_New procedure that you now have[/li][/ul]

That should be it. Close the template and base a new document on it - the code should run.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Hi Tony,

To test this i made a new document vbtest.dot. When I create a new document based on vbtest.dot, I get a document based on vbtest.dot, but nothing happens.

Is there something else I have to do?

Thx in advance

Ewald
 
No, you shouldn't have to do anything else.

Code in a Document_New procedure in a template's ThisDocument module should run automatically when a new document is based on the template - unless you have macros disabled.

Just to be absolutely sure - vbtest.dot is a Word template, isn't it? Just giving it a .dot suffix doesn't make it a template, you must save it as a template.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Hi Tony,

Tnx in the first place.

You were right. The security for macro's were set to maximum. They have been set the medium now.

Thnx for the help so far.[thumbsup2]

Gr.
Ewald
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top