Office Word Programming >> Problem updating word document from and Add-In

by robert » Tue, 20 Feb 2007 02:07:43 GMT

Hi,
I'm developing an Add-In in C# for Word 2007 using VSTO for VS2005.
Part of the excercise is to monitor pictures on disk that have been
linked into a word document as an inlineshapes collection. Once a
picture file is being changed by a picture editor then the Add-In
needs to update the document with the revised image. To that end I've
used the FileSystemWatcher object, set it to monitor fileextensions
and the path with the concerned pictures. In the corresponding
OnChange eventhandler I issue the call

Word.Document doc =
Globals.ThisAddIn.Application.ActiveDocument;
doc.Fields.Update()

There are other properties of the document that also need to change
such as bookmark names. Trying to do that in the OnChange function
generates an error usually along the lines that "the object is locked
for format changes".

Does anyone know how to get around this? For the
FileSystemWatcherObject I have set its SynchronizingObject = this,
i.e. assigned it to the C# Add-In usercontrol.

Many thanks for any suggestions,

Rob



Office Word Programming >> Problem updating word document from and Add-In

by Jezebel » Tue, 20 Feb 2007 04:57:41 GMT


If the pictures are linked, you don't need to do anything to the Word
document: it will update automatically next time you open it.










Office Word Programming >> Problem updating word document from and Add-In

by robert » Wed, 28 Feb 2007 01:06:10 GMT

OK I seem to have circumvented the problem now. For my task it's
important that the inlineshape pictures are updated instantaneously.
So having to reopen the document was no good. Trying simultaneously to
update bookmarks proved to be a nightmare since deleting a bookmark
programmatically Word also deletes the object encapsulated by the
bookmark (I find that counterintuitive).

rob








Similar Threads

1. Problems with Word Application.Add to add a document

I get the error below when I try to create a new word document in my C# 
application. I am using Application.Add method. The application works in the 
development environment (debug and release) but fails when compiled and is 
executed as a service. I believe it has to be permissions, what am I missing. 
Thanks.  
Message: HandlingInstanceID: f37dbec4-251b-4285-bc87-e8104324b222
<Exception>
<Description>An exception of type 
'System.Runtime.InteropServices.COMException' occurred and was 
caught.</Description>
<DateTime>2006-09-26 09:31:04Z</DateTime>
<ExceptionType>System.Runtime.InteropServices.COMException, mscorlib, 
Version=1.0.5000.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>There is insufficient memory. Save the document now.</Message>
<Source>Microsoft Word</Source>
<HelpLink>C:\Program Files\Microsoft 
Office\OFFICE11\1033\wdmain11.chm#24577</HelpLink>
<Property name="ErrorCode">-2146823191</Property>
<Property name="TargetSite">Word.Document Add(System.Object ByRef, 
System.Object ByRef, System.Object ByRef, System.Object ByRef)</Property>