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 / August 2005

Tip: Looking for answers? Try searching our database.

Keeping track of document windows

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jay - 05 Aug 2005 14:34 GMT
I'm wrting some VBA (using Windows NT and Word 97) that finds and
copies a few things from one document into a new (created by VBA)
document. I use...

 winSrc = ActiveWindow.Index
 Documents.Add
 winDst = ActiveWindow.Index
 Do
   ActiveDocument.Windows(winSrc).Activate
   'find something
   ...
   ...
   Selection.copy
   ActiveDocument.Windows(winDst).Activate
   Selection.Paste
 Loop while ...

The problem is that winSrc is assigned to 1, but when Documents.Add
adds a new document, this becomes Window number 1 so winDst is
assigned to 1 also. In the Word Windows menu, the original window is
renumbered to Window number 2, which seems strange but that's the way
VBA seems to work so I have to live with it. The result is that my
code doesn't work.

How do I find what my existing document is re-assigned to in VBA? In
this case, I know it's 2, but if I have several documents open, I
can't make this assumption. Alternatively, is there a better way to do
what I'm trying to do?
Jonathan West - 05 Aug 2005 21:00 GMT
Hi jay,

First of all, word from documents rather than dinwos, it will be much easier
to keep track of things.

Dim docSource as Document
Dim docDest as Document
Set docSource = ActiveDocument
Set docDest = Documents.Add

Once you assign an object variable to a document it will continue to
reference that document no matter whether the new documents are created, or
whether different documents are activated. You can do almost anything with
docSource or docDest that you can do with ActiveDocument.

Second, you can transfer formatted text between documents without using the
clipboard. Look up the FormattedText property in VBA help.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

> I'm wrting some VBA (using Windows NT and Word 97) that finds and
> copies a few things from one document into a new (created by VBA)
[quoted text clipped - 24 lines]
> can't make this assumption. Alternatively, is there a better way to do
> what I'm trying to do?
Jay - 11 Aug 2005 12:01 GMT
Thanks Jonathan, all is working well now.

> Hi jay,
>
[quoted text clipped - 42 lines]
> > can't make this assumption. Alternatively, is there a better way to do
> > what I'm trying to do?
 
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.