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
Solved

Open word doc with toolbar disabled using a process windows API

Posted on 2010-09-01
5
465 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

808 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