BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Activedocument in Word

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Glenn De Tollenaere
Guest





PostPosted: Fri Jan 23, 2004 1:01 pm    Post subject: Activedocument in Word Reply with quote



Hi all,

I have an application that uses Word to create and modify documents.
There is a problem however with the wordapplication.activedocument-property,
in the following case:
-a first document is being opened,
-another, second document is being opened,
-using the taskbar we switch back to the first document,

If I try to access wordapplication.activedocument in that case, I get the
reference to the second document (which is not the active one at that time).

Has anyone experienced this and knows how to solve or work-around this,
because this is a very annoying problem ?

Any help appreciated,
Glenn

PS Using the debugger (setting a breakpoint for instance) is no option,
because in that case you will get the correct document.



Back to top
Oliver Townshend
Guest





PostPosted: Sat Jan 24, 2004 5:23 am    Post subject: Re: Activedocument in Word Reply with quote



Quote:
I have an application that uses Word to create and modify documents.
There is a problem however with the
wordapplication.activedocument-property,
in the following case:
-a first document is being opened,

At this point you should save the reference to the doucment, eg
FirstDoc:=WordApp.ActiveDocument;

Quote:
-another, second document is being opened,
-using the taskbar we switch back to the first document,

If I try to access wordapplication.activedocument in that case, I get the
reference to the second document (which is not the active one at that
time).

Has anyone experienced this and knows how to solve or work-around this,
because this is a very annoying problem ?

Well you can find any document with code like Documents("Document1").Item
which will find the relevant document with that name. Programming with
ActiveDocument is always dangerous, as you never quite know what the user or
word will do.

Oliver Townshend



Back to top
Glenn De Tollenaere
Guest





PostPosted: Mon Jan 26, 2004 8:08 am    Post subject: Re: Activedocument in Word Reply with quote



Oliver,

that is the problem. I need to know in what document the user is working,
not the other way around !
The only way I know of to get the document the user is working on, is the
activedocument-property.

In the case described below however, it returns a wrong value
(documentvariable): the second document that has been opened instead of the
document the user is really working on.

I am aware of the documents("doc").item-option, but it will not solve my
problem here.

Regards
Glenn

"Oliver Townshend" <oliver (AT) zip (DOT) com.au> wrote

Quote:
I have an application that uses Word to create and modify documents.
There is a problem however with the
wordapplication.activedocument-property,
in the following case:
-a first document is being opened,

At this point you should save the reference to the doucment, eg
FirstDoc:=WordApp.ActiveDocument;

-another, second document is being opened,
-using the taskbar we switch back to the first document,

If I try to access wordapplication.activedocument in that case, I get
the
reference to the second document (which is not the active one at that
time).

Has anyone experienced this and knows how to solve or work-around this,
because this is a very annoying problem ?

Well you can find any document with code like Documents("Document1").Item
which will find the relevant document with that name. Programming with
ActiveDocument is always dangerous, as you never quite know what the user
or
word will do.

Oliver Townshend





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.