Solved

Open word doc with toolbar disabled using a process windows API

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
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…

747 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

13 Experts available now in Live!

Get 1:1 Help Now