Solved

Open word doc with toolbar disabled using a process windows API

Posted on 2010-09-01
5
460 Views
Last Modified: 2013-11-07
Hello I have the fiollowing scenario
I would like to open a word document from a vb.net application using a process
I am currently doing the following


Dim startInfo As New ProcessStartInfo()
        startInfo.FileName = "WINWORD.EXE"
        IO.File.SetAttributes(fileName, FileAttributes.ReadOnly)
        startInfo.Arguments = fileName
        Process.Start(startInfo)

Which seems to work fine, but I would like to get access to the document object launched by the process , the reason being after the process is started I would like to set some attributes of the document itself example the protection mode

I do not want to only open the document in readonly mode but I would also like to disable the word toolbar (gray it out)

I know I could have launched the document as follows
dim app as Word.Application
app = New Word.Application()

          document = app.Documents.Open(fileName)
          document.ActiveWindow.WindowState = Word.WdWindowState.wdWindowStateNormal

but need a handle to the process, which is critical in my case

what would be ideal is if I can do app.getHandle() or findHandle(app)?

Any way I could resolve this or alternatives to achieve what I want

Thank you
0
Comment
Question by:xav056
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:cquinn
ID: 33584623
This article shows how to get the WindowHandle of an automation application in VBA - it should be easy enough to convert it to work in .Net

http://support.microsoft.com/kb/258511
0
 
LVL 9

Author Comment

by:xav056
ID: 33584769
This will not work as I do not want to get any word app (findwindow) by class name
this will cause a problem when I have more than one document open
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 33586915
<<<<this will cause a problem when I have more than one document open>>>>
If I understand the KB article cited by cquinn correctly, you can assign a unique caption to each of the open documents and use that to retrieve the handle.

Excerpt
Find the Window Handle for an Application That Can Have Multiple Instances
Some applications, such as Microsoft Excel or Microsoft Word, can have multiple instances running at the same time. To retrieve the handle to the application instance that you are automating, you can first use Automation to change the title of the application to a unique value and then use the FindWindow API function to retrieve its window handle. The following steps illustrate this technique by using Microsoft Excel as the Automation server.
0
 
LVL 9

Author Comment

by:xav056
ID: 33587753
this is what I waould like to avoid, if a file is read only word will append (readonlt) to the caption, if the file is being open on a system with a non englisg culture it might have a different caption,
I would like to avoid this approach and user the findWindow method
I would like to be able to get the handle as soon as I launch the application or use a process to launch the app but then be able to get a reference top the object launched by the process
Thank you
0
 
LVL 38

Accepted Solution

by:
puppydogbuddy earned 500 total points
ID: 33592318
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

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
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 video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
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 …

930 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

14 Experts available now in Live!

Get 1:1 Help Now