Solved

Open word doc with toolbar disabled using a process windows API

Posted on 2010-09-01
5
471 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
[X]
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
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

728 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