Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

File Open not active document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JRob - 28 Sep 2007 15:37 GMT
I am in the process of migrating from Word 2002 to Word 2007 and have
several macros developed in the later.

One macro opens files using the Documents.Open(strFileName)

Previously the file opened would become the activedocument in the Word
Application window. However in Word 2007 the file opened is not the
activedocument and it has to be selected from the task bar or by using
Alt + Tab.

I have tried various workarounds to sort this (SendKeys etc) to no
avail. Any ideas would be welcome.
Jay Freedman - 28 Sep 2007 17:23 GMT
> I am in the process of migrating from Word 2002 to Word 2007 and have
> several macros developed in the later.
[quoted text clipped - 8 lines]
> I have tried various workarounds to sort this (SendKeys etc) to no
> avail. Any ideas would be welcome.

The most recently opened document should become the ActiveDocument, and I'm
not sure what would interfere with that. Unfortunately I'm away from my copy
of Word 2007 right now, so I can't test it to see if it behaves the same as
yours.

In any case, you can force it this way:

 Dim wdDoc As Document
 Set wdDoc = Documents.Open(strFileName)
 wdDoc.Activate

If the document is already active, calling Activate on it won't do anything.

Technically, you can do this in one statement,

  Documents.Open(strFileName).Activate

but it's usually a good idea -- especially when there are two or more
documents open at the same time -- to use an assigned Document object like
wdDoc to do all operations in the macro instead of using the ActiveDocument
object. Then you always know which document is going to be the target of the
operation. In fact, the document doesn't even have to be active to do things
like formatting, data extraction, Find/Replace, etc.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Tony Jollans - 28 Sep 2007 17:58 GMT
I'll second Jay on that. Do you have any AddIns (or code in the document or
its template) that might be doing something to change the ActiveDocument?
What do you see as you step through the code?

Signature

Enjoy,
Tony

>> I am in the process of migrating from Word 2002 to Word 2007 and have
>> several macros developed in the later.
[quoted text clipped - 33 lines]
> the target of the operation. In fact, the document doesn't even have to be
> active to do things like formatting, data extraction, Find/Replace, etc.
JRob - 29 Sep 2007 12:36 GMT
Thank you both for your replies. I will not be back in the office
until Monday so will try your suggestions then.
JRob - 01 Oct 2007 10:32 GMT
The file selection to open was displayed in a dialog box.
Interestingly

doc.Activate
Unload Me   (unloading the dialog box)
does not make doc the active document

However:
Unload Me
doc.Activate
works perfectly
Russ - 02 Oct 2007 07:11 GMT
JRob,

> The file selection to open was displayed in a dialog box.
> Interestingly
>
> doc.Activate
> Unload Me   (unloading the dialog box)
> does not make doc the active document
The above probably did not work because you opened the dialog in the default
modal (versus modeless) way, which meant that nothing could be selected
(activated) while the form (dialog) was still being shown.

> However:
> Unload Me
> doc.Activate
> works perfectly

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.