Activate desired document

S

Steve C

I program in Word 2003, but many of our office employees still have 2000.
I'm puzzled by the behavior of one of my automated templates between the two
versions.

In 2003, I set up a blank template called MasterBidTemplate.dot. Upon
launching it (using File > New), a form displays asking for various
information. It also asks the user to choose from a combo box which of 15-20
available documents he/she would like to dump that form information into.

Upon clicking OK in 2003, the desired document displays (i.e., it is the
active document and the user sees it). The blank document left from the use
of the template is minimized.

In 2000, it's the opposite: the blank document is the active document that
the user sees while the desired document is minimized.

I need some help with my code to tell Word to activate (display) the desired
document instead. Thanks for any suggestions you have!
 
S

Shauna Kelly

Hi Steve

The general rule is to avoid using ActiveDocument more than once. Get a
reference to the ActiveDocument as soon as you can (ie before Word has a
chance to change its mind) and then use the reference.

So:
Dim oNewDoc as word.document

'As soon as possible after creating the new document,
'get a reference to it
set oNewDoc = ActiveDocument

'Thereafter, use oNewDoc, eg:
oNewDoc.range.insertafter "hello world"

I assume you give your users a list of these 15-20 documents and they
choose a path and file name. So, when you want to open that document:

Dim sUserPFN as string
Dim docUser as Word.document

'Get the sUserPFN from the user via your form.
'So sUserPFN is, eg, "c:\whatever\wherever\something.doc"

'Open the document
set docUser = Documents.Open(sUserPFN)

'And if you want to Activate it, you can
docUser.Activate

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
S

Steve C

Thanks, Shauna. Once I identified the document as you suggested, I was able
to activate the one I wanted. I appreciate your help!
 

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