Consulting

Results 1 to 3 of 3

Thread: Open A Template File from a Macro

  1. #1

    Triggering a template macro from another template file.

    Hi guys,

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

    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:[VBA] Document.Open("Letter.dot")[/VBA]
    it only opens the file and does not trigger the macro to read in the data from the temp text file. Using something like:

    [VBA] Dim w As Object

    Set w = CreateObject("Word.Basic")

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


    Set w = Nothing
    [/VBA]


    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

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Take a look at the following.
    [vba]Documents.Add template:= _
    "C:\Documents and Settings\Gerry\" _
    & "Application Data\Microsoft\Templates" _
    & "\test2.dot"[/vba]
    will make a new document USING the template. Auto macros will fire, as does Document_New.
    [vba]Documents.Add
    ActiveDocument.AttachedTemplate = _
    "C:\Documents and Settings\Gerry\" _
    & "Application Data\Microsoft\Templates" _
    & "\test2.dot"[/vba]
    will make a new document, then attach the template. Auto routines do NOT fire, Document_New does NOT fire.

  3. #3
    Oh awesome!!

    Thanks, ive been waiting all day for a reply!

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •