Solved

How to get a handle to a Word document window?

Posted on 2015-01-14
5
481 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Spell Check in VB6 13 96
Microsoft Word Add-in Start automatically 8 46
copy the content of word to outlook 3 49
Recover lost Hyperlink destination/target in OneNote 3 29
Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

910 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

23 Experts available now in Live!

Get 1:1 Help Now