• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 481
  • Last Modified:

Open word doc with toolbar disabled using a process windows API

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
xav056
Asked:
xav056
  • 2
  • 2
1 Solution
 
cquinnCommented:
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
 
xav056Author Commented:
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
 
puppydogbuddyCommented:
<<<<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
 
xav056Author Commented:
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

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now