Activate desired document

Activate desired document

Post by U3RldmUgQ » Sat, 26 Jan 2008 07:43:39

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

In 2003, I set up a blank template called 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!
Steve C

Activate desired document

Post by Shauna Kel » Sat, 26 Jan 2008 09:03:54

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.

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

Hope this helps.

Shauna Kelly. Microsoft MVP.


Activate desired document

Post by U3RldmUgQ » Sun, 27 Jan 2008 00:48:01

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

Steve C