anonymous
Fri Aug 06 14:43:13 CDT 2004
Jay,
Thank you for all of your help. Your VBS code was just
what I needed.
THANKS!!!!!!!!!!!
Gilley
aka Dilbert!
>-----Original Message-----
>Hi Gilley,
>
>Sorry, that was one of the little factoids I had
forgotten: Launching Word
>with a /t switch does not start any auto macros, by
design. For example, see
>the last post, from Cindy Meister, in this thread:
>
http://groups.google.com/groups?threadm=%
23oqSCxhdDHA.1884%40TK2MSFTNGP10.phx.gbl
>
>However, there is a workaround.... If your DOS command
line launches a small
>VBScript file, which in turn uses automation to start
Word and create a new
>document based on the template, the auto macro *will*
run. Here's VBS code
>that works for me (you'll have to fill in the <username>
in the path to your
>template folder, and use the name of your template):
>
>Dim oWord
>On Error Resume Next
>
>Set oWord = GetObject("Word.Application")
>If oWord Is Nothing Then
> Set oWord = CreateObject("Word.Application")
>End If
>
>If oWord Is Nothing Then
> MsgBox "Could not start Word"
>Else
> oWord.Visible = True
> ' the following command must all be one line
> oWord.Documents.Add("C:\Documents and
Settings\<username>\Application
>Data\Microsoft\Templates\test_auto.dot")
>End If
>
>I saved this code in a text file that I named
C:\temp\automacro.vbs, and
>then I just typed the name of that file in a DOS command
line. The
>test_auto.dot template I used had both an AutoNew()
procedure in a regular
>module and a Document_New() procedure in the ThisDocument
module, and they
>both ran (in that order).
>
>--
>Regards,
>Jay Freedman
>Microsoft Word MVP FAQ:
http://word.mvps.org
>
>Gilley wrote:
>> Jay,
>>
>> Thanks for the very quick reply, but I am still having
>> trouble. (Sometimes I can be a little 'slow'!:))
>>
>> Based on the information you provided, I now have the
>> macro running when I start a new document based on the
>> template. THANKS!
>>
>> Is there an issue with launching a new document based
on a
>> template from a command line? This is where I think my
>> problem lies now!
>>
>> Thanks again,
>> Gilley
>>> -----Original Message-----
>>> Hi Gilley,
>>>
>>> Your problem is the wrong choice of an event -- you
want you code to
>>> run on the New event, not the Open event. That means
you should name
>>> your macro Document_New(). See
>>
http://word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm.
>>>
>>> --
>>> Regards,
>>> Jay Freedman
>>> Microsoft Word MVP FAQ:
http://word.mvps.org
>>>
>>> Gilley wrote:
>>>> I have looked through and followed (to the best of my
>>>> ability) the instructions on the MVP web site
regarding
>>>> having macros run when a document is opened based on a
>>>> specific template.
>>>>
>>>> Let me explain what I need to do:
>>>>
>>>> I need a DOS (yes DOS) based application to:
>>>> 1. Open Word.
>>>> 2. Launch a template.
>>>> 3. Run a mail merge macro.
>>>> 4. Print the results.
>>>> 5. Close Word.
>>>>
>>>> I have accomplished 1 and 2 by envoking Word from a
>>>> command line using the /t switch to open a new
document
>>>> based on a specific template.
>>>>
>>>> I have accomplished 3, 4, and 5 in a macro.
>>>>
>>>> The problem is that I can't seem to figure out how to
get
>>>> 3, 4, and 5 to happen automatically when a new
document is
>>>> opened based on the template.
>>>>
>>>> I have tried using the Document_Open() procedure.
>>>> However, I can only get it to work when I open the
>>>> template, not when a new document is created based on
the
>>>> template.
>>>>
>>>> What am I missing?
>>>>
>>>> Thank bunches in advance for your help.
>>>>
>>>> Gilley
>>>
>>>
>>> .
>
>
>.
>