PDA

View Full Version : Open A Template File from a Macro



BlueDNA
12-04-2005, 06:28 PM
Hi guys,

I'm very new to VBA and the forum so please be nice! :hi:

Coming from an OOP background and now im asked to do some VBA stuff its all very scary! I've gone pretty far all alone, but ive run into a problem and ive google'd everywhere but havent found a solution yet.

Essentially what im trying to do is create a macro (Menu.dot) that:
- Prompts the user for a document type (i.e. Letter, Memo, Minutes, etc) that they would like to create (through a series of menus)
- Accepts the relevant generic input data (i.e. To: Firstname, Surname, etc, CC: firstname, surname, etc)
- Writes the input data into a temp text file.
- Then from the template file open another template file (from Menu.dot->Letter.dot) which has a macro to read data in from the temp text file and map them into the bookmarks on that template file.
- Save the document as a new .doc file (i.e. NewLetter.doc)
- Then close.

Pretty sexy stuff, but im having one little problem. I've basically achieved everything except being able to open another template from a template file.

When i open another template file using: Document.Open("Letter.dot")
it only opens the file and does not trigger the macro to read in the data from the temp text file. Using something like:

Dim w As Object

Set w = CreateObject("Word.Basic")

w.AppMaximize
w.FileOpen "Letter.dot"'

Set w = Nothing


The aboove method does the same thing, However when i double click on Letter.dot, the macro is launched and does everything i want it to do (autonew() launches and reads the temp text file and populates the bookmarks, saves and closes.)

Im hoping its not a big task to get this missing link. If anyone can help or provide a work around i would really really really appreciate it!!!

Thanks in advance!

BlueDNA :hi:

fumei
12-04-2005, 10:22 PM
Take a look at the following.
Documents.Add template:= _
"C:\Documents and Settings\Gerry\" _
& "Application Data\Microsoft\Templates" _
& "\test2.dot"
will make a new document USING the template. Auto macros will fire, as does Document_New.
Documents.Add
ActiveDocument.AttachedTemplate = _
"C:\Documents and Settings\Gerry\" _
& "Application Data\Microsoft\Templates" _
& "\test2.dot"
will make a new document, then attach the template. Auto routines do NOT fire, Document_New does NOT fire.

BlueDNA
12-04-2005, 10:36 PM
Oh awesome!!

Thanks, ive been waiting all day for a reply!

You the man Gerry, but im sure you've heard that many times! =)