Solved

How to get a handle to a Word document window?

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

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 15

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

840 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