Transparently saving a Word Add In

K

Kevin

I'm writing a C# add in for Word XP and 2003 which adds a button to
the Word toolbar. My intent is that when the user clicks this button
the document they are working on will be saved to a central
repository. Beyond that, I do not wish to interrupt the normal
operation of Word, and I do not want to force the user to save their
document.

My problem is this: if my add in uses the Word "Save As" feature to
save the document to the repository then I've effectively broken the
standard "Save" feature because all changes will now be saved to the
document in the repository unless the user does another "Save As". I
can't save it to my repository and then back to their original
location because I don't want to require that they've saved their
document at all prior to using my add in.

I'm supposing my answer involves creating a new document, inserting
the entire contents of their current document into it, and then saving
it. I attempted to achieve this with copy and paste but this approach
didn't transfer all of the objects in my source document into the
target document (in particular images didn't seem to transfer this way
, but I may need to test this again). I'd also didn't like having to
modify the clipboard contents in fear that the user might lose what
they had there. Another concern is that page margins and such don't
come over with copy and paste, and my real goal to have the document
appear exactly as if they saved it themselves.

I feel like this should be easy to accomplish but I'm really running
into a wall here. Any help would be greatly appreciated. Thanks.

Kevin S.
 
C

Cindy M -WordMVP-

Hi Kevin,

If this were Word 2003, then you might be able to do something with
XML...

As it is, if you need to have the entire document (including page
setup), then you're pretty much stuck with Copy/Paste OR

You could use the Document.Content.FormattedText property, which would
avoid the clipboard. The only problem with this is that it does NOT pick
up the page setup settings for the last section of the document. So your
application would also have to read these from the current file and
apply them (things like margins, headers, footers).
I'm writing a C# add in for Word XP and 2003 which adds a button to
the Word toolbar. My intent is that when the user clicks this button
the document they are working on will be saved to a central
repository. Beyond that, I do not wish to interrupt the normal
operation of Word, and I do not want to force the user to save their
document.

My problem is this: if my add in uses the Word "Save As" feature to
save the document to the repository then I've effectively broken the
standard "Save" feature because all changes will now be saved to the
document in the repository unless the user does another "Save As". I
can't save it to my repository and then back to their original
location because I don't want to require that they've saved their
document at all prior to using my add in.

I'm supposing my answer involves creating a new document, inserting
the entire contents of their current document into it, and then saving
it. I attempted to achieve this with copy and paste but this approach
didn't transfer all of the objects in my source document into the
target document (in particular images didn't seem to transfer this way
, but I may need to test this again). I'd also didn't like having to
modify the clipboard contents in fear that the user might lose what
they had there. Another concern is that page margins and such don't
come over with copy and paste, and my real goal to have the document
appear exactly as if they saved it themselves.

I feel like this should be easy to accomplish but I'm really running
into a wall here.

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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top