VSTO Document SaveAs

S

SurfBoy

the following code will SaveAs to a file, but the document is always empty.

Even saving as different file types. I have tried every possible event, like
ThisDocument_CloseEvent
ThisDocument_New
ThisDocument_BeforeClose
ThisDocument_AvtivateEvent...

ThisApplication.ActiveDocument.SaveAs() AND just SaveAS()

.any ideas?

object FileName = @"C:\mydoc.doc";
object FileFormat = Word.WdSaveFormat.wdFormatDocument;
object LockComments = false;
object AddToRecentFiles = true;
object ReadOnlyRecommended = true;
object EmbedTrueTypeFonts = true;
object SaveNativePictureFormat = true;
object SaveFormsData = true;
object SaveAsAOCELetter = false;
object Encoding = 20127;
object InsertLineBreaks = false;
object AllowSubstitutions = false;
object LineEnding = Word.WdLineEndingType.wdCRLF;
object AddBiDiMarks = false;

ThisApplication.ActiveDocument.SaveAs(ref FileName, ref FileFormat, ref
LockComments, ref missing, ref AddToRecentFiles, ref missing, ref
ReadOnlyRecommended, ref EmbedTrueTypeFonts, ref SaveNativePictureFormat, ref
SaveFormsData, ref SaveAsAOCELetter, ref Encoding, ref InsertLineBreaks, ref
AllowSubstitutions, ref LineEnding, ref AddBiDiMarks);
 
C

Cindy M.

Hi =?Utf-8?B?U3VyZkJveQ==?=,
the following code will SaveAs to a file, but the document is always empty.
Well, have you put anything INTO the document? Have you tried
ThisDocument.SaveAs?
Even saving as different file types. I have tried every possible event, like
ThisDocument_CloseEvent
ThisDocument_New
ThisDocument_BeforeClose
ThisDocument_AvtivateEvent...

ThisApplication.ActiveDocument.SaveAs() AND just SaveAS()

.any ideas?

object FileName = @"C:\mydoc.doc";
object FileFormat = Word.WdSaveFormat.wdFormatDocument;
object LockComments = false;
object AddToRecentFiles = true;
object ReadOnlyRecommended = true;
object EmbedTrueTypeFonts = true;
object SaveNativePictureFormat = true;
object SaveFormsData = true;
object SaveAsAOCELetter = false;
object Encoding = 20127;
object InsertLineBreaks = false;
object AllowSubstitutions = false;
object LineEnding = Word.WdLineEndingType.wdCRLF;
object AddBiDiMarks = false;

ThisApplication.ActiveDocument.SaveAs(ref FileName, ref FileFormat, ref
LockComments, ref missing, ref AddToRecentFiles, ref missing, ref
ReadOnlyRecommended, ref EmbedTrueTypeFonts, ref SaveNativePictureFormat, ref
SaveFormsData, ref SaveAsAOCELetter, ref Encoding, ref InsertLineBreaks, ref
AllowSubstitutions, ref LineEnding, ref AddBiDiMarks);

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :)
 
S

SurfBoy

Yes, of course, the document contains data.
I have tried both ThisDocument.SaveAs() and
ThisApplication.ActiveDocument.SaveAs()

To summarize:

In the Project, from designer...
Create WebReference to WebService (service returns TypedDataSet)
Create BindingSource with DataSource pointing to the
WebService.TypedDataSet and DataMember pointing to a Table.
Create Bookmark and set DataBinding of Text to BindingSource - ColumnName

In ThisDocument_Startup...
Call WebService and retrieve TypedDataSet (I verified that data exists).
Set BindingSource.DataSource = retrieved TypedDataSet
Do SaveAs() as coded.

The saved document is blank, and the Saved property is still false.
When I try to close the document now manually it prompts me to save, which I
can do successfully. Automating the SaveAs() in Startup has been problematic.
 
C

Cindy M.

Hi =?Utf-8?B?U3VyZkJveQ==?=,
Yes, of course, the document contains data.
I have tried both ThisDocument.SaveAs() and
ThisApplication.ActiveDocument.SaveAs()

To summarize:

In the Project, from designer...
Create WebReference to WebService (service returns TypedDataSet)
Create BindingSource with DataSource pointing to the
WebService.TypedDataSet and DataMember pointing to a Table.
Create Bookmark and set DataBinding of Text to BindingSource - ColumnName

In ThisDocument_Startup...
Call WebService and retrieve TypedDataSet (I verified that data exists).
Set BindingSource.DataSource = retrieved TypedDataSet
Do SaveAs() as coded.

The saved document is blank, and the Saved property is still false.
When I try to close the document now manually it prompts me to save, which I
can do successfully. Automating the SaveAs() in Startup has been problematic.
Mmm, it's still not clear to me whether the document is displaying text to
begin with, or only after you've put data in the data cache. And whether
closing it is removing EVERYTHING in the document, or just what you've put in
the data cache.

And you say if you do a manual save everything is exactly the way it should be?
The problem is only when using SaveAs?

Word has a little problem: sometimes it doesn't recognize something has been
changed (a document property is one common scenario), so won't save anything.
It sounds as if this could be what you're encountering. To test this, add a
statement to your code that writes a single character into the file, then do
the SaveAs. If the results are consistently good, then this is the problem
you're encountering. In that case, delete (do not use Undo) the character
you've inserted so that Word will still recognize the document as "dirty" and
you should be OK.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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