Solved

How to get a handle to a Word document window?

Posted on 2015-01-14
5
420 Views
Last Modified: 2015-02-10
Suppose you have VB6 connected to a created Word document, or as a Word add-in, or from VBA, anyway, you have access to the Word.Application and Word.Document objects.
How to get a handle to the Word document window , but without using something like FindWindow and then searching for a window with a specific title or class name? Does Word expose it somewhere? I don't trust in FindWindow, as several documents can have the same document title/caption...
0
Comment
Question by:npaun
  • 2
  • 2
5 Comments
 
LVL 12

Expert Comment

by:James Elliott
ID: 40549040
Excel has an hwnd property under Excel.Application. I do not believe Word does, so I think you're limited to API calls that you want to avoid.
0
 
LVL 12

Assisted Solution

by:James Elliott
James Elliott earned 250 total points
ID: 40549041
0
 
LVL 14

Expert Comment

by:DrTribos
ID: 40549968
Ooops sorry - posted a suggestion using FindWindow... read the Q on my phone so missed that.  

Anyway, appreciate that Find Window can have many windows with the same name.  I guess you could find the first instance of the window (change the name) then look for a 2nd instance and so on... you could also, presumably, interrogate the object for some other known properties?
0
 

Author Comment

by:npaun
ID: 40570146
...
0
 
LVL 14

Accepted Solution

by:
DrTribos earned 250 total points
ID: 40571821
Ok, not really sure where you are up to with this but I am using find window in MS Word however if I need to be sure I get the right window I change the window caption by adding a prefix:

strWindow =  activedocument.Windows(1).Caption
activedocument.Windows(1).Caption = myuniqueprefix & activedocument.Windows(1).Caption

then I look for that window with FindWindow
then I change the caption back to what it was:
activedocument.Windows(1).Caption = strWindow

It works for me :-)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now