Solved

How to get a handle to a Word document window?

Posted on 2015-01-14
5
672 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show you how to use shortcut menus in the Access run-time environment.
Outlook Free & Paid Tools
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
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…

730 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