Office Word Programming >> Activating a document

by markl59@gmail.com » Mon, 11 Sep 2006 23:46:49 GMT

Hi,
I'm building a macro that buils and opens a new document from a User
Form contained in the current document. When I've built the new
document I want to close the current one and activate (or bring to the
front) the new one. However if I already have documents open, I
activate the new one but then the code to unload the old one appears to
reactivate it. Then when it does unload, focus goes to the first open
document., not my current one. Is there a way I can activate the new
doc without 'losing focus' when further code runs in the old one
(though it is only a Close ).
Thanks for any ideas,
Mark



Office Word Programming >> Activating a document

by Jezebel » Tue, 12 Sep 2006 06:43:43 GMT


1. The code shouldn't be in any document. It should be in a global template
or an add-in. That way the code is not affected by the documents you open or
close.

2. When you create the document, get a reference to it; then active that
reference --

Dim pDoc as Word.Document
set pDoc = Documents.Add(Template:="...)
:
pDoc.Activate











Similar Threads

1. To expand sub documents when activating a document

Hi,

I am opening a document from my c# code. The document 
itself is containing two subdocuments. When I activate the 
document to open it, it gets opened but the subdocuments 
in it appear in hyperlind and not in expanded mode.
I have however explicitly stated the following code to 
expand all subdocuments, but failed-

aDoc.ActiveWindow.ActivePane.View.Type = 
Word.WdViewType.wdOutlineView;

WordApp.ActiveDocument.Subdocuments.Expanded = true;

Can anyone suggest whatz wrong with that.
How to get subdocuments expanded when opening the master 
document.


Thx.
Sandeep



2. Activating correct document after closing a document - Word VBA

3. using excel macro to activate word document

I have a bunch of data in Excel that I would like to copy 
and paste into a Word document to create different 
tables.  I have written a macro in Word to format these 
tables once the excel data is copied over.

Is there a way I can use an Excel macro to automatically 
select a block of cells, copy and paste into Word, and 
activate the Word macro?

Thanks,

Amy

4. Activating a document that has visual basic text and form fields - Word Document management

5. "activate" Active Document with code

After I run my code, when I try to use the toolbar, nothing happens.  It
acts as if it's frozen.  If I click on the window in the toolbar (which
shuts the active document) and then re-click on the window in the task bar,
my toolbar now is functional again.

How can I programmatically get around this (having to mouse-click off and
then on the active window) after running my code?  (Neither
Activedocument.Activate nor Activedocument.Select does it.)

TIA


6. Activate desired document - Word VBA

7. Activate assigned document

I have a code that is creating and filling a new document with a template as
base. Herefore the user is requested to enter some specific data in an
userform, activated through a custom toolbarbutton. After code running I
would like to set the focus to this new document but somehow it doesn't
work.

I tried:
Documents(1).Activate
Windows(ActiveDocument.Name).Activate
Application.ScreenRefresh

and other combinations. I see that while code is running the new window is
activated but after the code is ended the focus is returned to the document
in which the code was started.

Any suggestions would be most welcome.

Alexander


8. How to activate a document to accept a Drawing Arrow? - Word Document management