Re: Word automation, etc.



Hi Cindy,

Thanks so much for your input. I appreciate it!

Off the current subject, I was having a bit of trouble closing out the word
instance. I don't understand why it didn't work the way I had it and after a
modification to the code it does work now. Basically, when the application
starts it creates an instance of word. If I then quit the application before
a document was loaded, the word instance wouldn't die. If a document is
loaded first then the app is quit, the word instance goes away.

Anyway, here is the previous code (that wouldn't kill the word instance):

public void CloseControl()
{
object dummy = System.Reflection.Missing.Value;
object dummy2 = (object)false;

try
{
document.Close( ref dummy2, ref dummy, ref dummy );
wd.Quit( ref dummy2, ref dummy, ref dummy );
}
catch {}
}

This would give the "The Object invoked has disconnected from the clients"
error when I would quit the app without loading a document.

When I changed the code such that the .Close and .Quit methods were in
separate try/catch blocks, the instance of word is killed and I don't get the
error.

public void CloseControl()
{
object dummy = System.Reflection.Missing.Value;
object dummy2 = (object)false;

try
{
document.Close( ref dummy2, ref dummy, ref dummy );
}
catch {}

try
{
wd.Quit( ref dummy2, ref dummy, ref dummy );
}
catch{}
}

Any ideas why this happens?

David

"Cindy M -WordMVP-" wrote:

> Hi =?Utf-8?B?d2lsc29uZA==?=,
>
> > We will
> > be using Word 2003. The development environment is .NET (2003) and C#.
> >
> OK, this opens up additional possibilities for you. One is XML. You could,
> for example, dump all the document content and formatting into a "blank"
> document in the form of XML. This won't carry across everything (some of
> the page layout stuff, for example), but it would certainly be faster than
> automating the creation of a document from scratch. (This in answer to
> creating a new document from a URL, via d/l from a Web Server).
>
> You can also extract the content of a document the same way. Or, if you
> don't need the entire document, just certain parts, you can parse the XML
> and extract only what you need.
>
> > I have to check with the super on the tab key issue. I don't know if she
> > will allow me to use anything other than tab. If that's the case, I'll
> > probably go the keybindings/macro route...
> >
> Word 2003 provides a special kind of document protection: you can
> lock/unlock specific document ranges for editing. There's a task pane that
> lets the user move from editable area to editable area.
>
> There's also the possibility of protecting a document as a form and using
> Form Fields (then you can TAB). And there are ActiveX controls that can be
> used with forms protection. The biggest issue with forms protection comes
> if the user needs to do more than just enter text content. Formatting,
> headers, footers and graphics (basically) are locked out with forms
> protection active.
>
> What might be very interesting for you would be VSTO 2005 (for that, you
> need VS 2005), where you can use data-caching, create custom task panes and
> provide a wide range of controls (including Windows controls you create
> yourself).
>
> SmartDocument solutions might also be something for you to consider
> (especially if VSTO 2005 isn't an option). There you place XML tags in your
> document. You then define what should appear in a special task pane to aid
> the user with the expected in-put. (Including displaying lists from
> databases, and even sending data back through the list.)
>
> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
> http://www.word.mvps.org
>
> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)
>
>
.



Relevant Pages

  • Re: Word automation, etc.
    ... One is XML. ... dump all the document content and formatting into a "blank" ... Word 2003 provides a special kind of document protection: ... And there are ActiveX controls that can be ...
    (microsoft.public.office.developer.automation)
  • RE: Databinding bookmarks as "read-only"
    ... issues with programmatically inserting and binding this number of controls at ... and document protection and then programmatically toggle document protection ... For more information regarding Visual Studio Tools for Office 2005: ...
    (microsoft.public.vsnet.vstools.office)
  • Re: Why does Design Mode turn on when opening a protected file?
    ... design mode, protection, etc. ... But it still comes up in Design Mode while ... > textboxes) and then protecting the document so that those controls are ...
    (microsoft.public.word.vba.general)
  • Re: Start enforcing protection greyed out
    ... to find Doug's answer to Rita in another post, ... I have no Active X controls in my form but it is still greyed ... "Stefan Blom" wrote: ... document, the Yes, Start Enforcing Protection button is grayed out. ...
    (microsoft.public.word.docmanagement)
  • Re: Content and legacy controls
    ... Another alternative is to use the Active X Checkbox control. ... Text content controls. ... So I removed protection, selected the entire document and added a Rich text ... protection and allow editing of controls. ...
    (microsoft.public.word.docmanagement)