How do I get the Windows Handle of an ActiveDocument in Microsoft Word?
I wish to save the handle value to a variable.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the FindWindow function to get the handle of the window in a currently active word application:
The class name for MS Word is “OpusApp”. If you have only the one Word app open then the following would return the handle to that window:
Note when you have multiple active Word applications, you can add the name of the window caption. For example if its saved as “Stanigator.doc”, then the caption would read as “Stanigator – Microsoft Word”. So:
The other API that may come in handy is:
Edit:
I was going to recommend the VSTO approach but based on this link that doesn’t appear to be wise:
Connect Issue: VSTO API support for MS Word Main Window Handle