Variable path to WINWORD.exe; how can I automate WORD startup?

F

Franky G

Hi,

At the moment I'm using a Macro in Access 2000 to Start MS
Word(2000)with a specific template, which is working fine. However,
some staff have moved onto XP/ Office XP PC's while I'm developing on
W2k. The problem is that the path to WINWORD.exe is different, and the
Macro can't handle that.

So I suppose I'm asking whats the best way to Start WORD from within
Access with a specific template, irrespective of what the path to
WINWORD.exe is?!

Thanks for any help,

FrankyG
 
M

Malcolm Smith

I think that you need to rethink what is happening with Word.

Word doesn't start with a template at all. It's only documents that have
templates and not the application itself.

So, all you need to do is to create an instance of Word, make sure that
there are no documents within that instance and then create a new document
based upon a template.

Something like this (untested) code:


Sub CreateNewDocument (sTemplateName as string)

Dim oWord as Word.Application
Dim oDocument as Document
Dim sWorkgroupTemplatePath as string
Dim sWorkgroupTemplate as string


set oWord = New Word.Application
do while oWord.Documents.Count > 0
oWord.Documents(1).Close wddonotsavedocument
loop

sWorkgroupTemplatePath = _
oWord.Options.DefaultFileLocation(wdWorkgrouptemplatefolder)
sWorkGroupTemplate = _
sWorkgroupTemplatePath & "\" & sTemplateName

if len(dir$(sworkgrouptemplate)) > 0 then
' Template exists
oDocument = oWord.Documents.Add sWorkgroupTemplate
' The do all the work on the oDocument object
endif

End Sub


Not that I am not using the executable of Word, I am using Automation and
the COM interface to work out where things are. This is how things ought
to be done.

I am not sure if this code is 100% correct, but I am sure that this is
enough to get you going.

- Malc
www.dragondrop.com
 

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