Word Document saving vb.net

P

Peter W Johnson

Hi Guys,

I have an application written in vb.net that creates and saves a word
document.

We have just upgraded our office package from 2003 to 2007. Consequently our
members are now receiving their documents in 2007 format.

Is there anyway I can programmatically save the document in 2003 format in
my vb.net application?

Some code follows:-

' prepare word document for printing
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeFields

' Create an instance of Word and make it visible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True

' Add a new document.
wrdDoc = wrdApp.Documents.Add(*************a suitable template
file*************")
wrdDoc.Select()
wrdSelection = wrdApp.Selection()
wrdMailMerge = wrdDoc.MailMerge()

' Create MailMerge Data file.
Dim wrdDataDoc As Word._Document

' Create a data source at C:\DataDoc.doc containing the field
data.
wrdDoc.MailMerge.CreateDataSource(Name:="C:\DataDoc.doc",
HeaderRecord:="FullName, HomeStreet, HomeCity, HomeState, HomePostCode")

' Open the file to insert data.
wrdDataDoc = wrdApp.Documents.Open("C:\DataDoc.doc")

' Fill DataDoc.doc
' wrdDataDoc.Tables.Item(1).Rows.Add()
FillRow17(wrdDataDoc, (2), FullName, HomeStreet, HomeCity,
HomeState, HomePostCode)

' Save and close the file.
wrdDataDoc.Save()
wrdDataDoc.Close(False)


I am assuming that the "wrdDataDoc.Save()" code saves the document in the
default format. I am trying to save the document in a different format (2003
not 2007)

Cheers

Peter.
 
S

Scott M.

When I record myself saving in Word 2007 (but as the 97-2003 format), here
is the macro code that is created:

ActiveDocument.SaveAs FileName:="Doc5.doc",
FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True,
WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:= False

Now, I realize that this is the VBA incorporated into Word, but it should
give you some insight into the .NET proxy object's capabilities as it
pertains to saving. It looks like the Word constant "wdFormatDocument" is
the important item here.

-Scott
 
P

Peter W Johnson

Scott,

Thanks. I added:-

Const wrdFormatDocument = 0 (save in default format)

and added it to the saveas command. The extn (.doc) decides on what format
the document is saved as.

wrdMergedDoc.SaveAs("TaxInvoice" & MemberID & ".doc",
wrdformatdocument)


Many thanks

Peter
 

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

Similar Threads

save word after mail merge 1
Word from VB.Net 3
C# & Word Mail Merge Problems 3

Top