Question

I'm trying to save a Word 97-2003 document (.doc) using Delphi 6 and Word 2010.

Before Word 2010 everything worked fine with

WordDoc.SaveAs(FileName := FileName, FileFormat := wdFormatDocument);

where FileName := 'c:\doc.doc'

Now, Word 2010 presents an Save Dialog and I'm not sure why. I've tried the new SaveAs2 method

WordDoc.SaveAs2(FileName := FileName, FileFormat := wdFormatDocument, CompatibilityMode:= wdWord2003);

but with the same result.

Oddly,

WordDoc.SaveAs2(FileName := FileName, FileFormat := wdFormatDocumentDefault, CompatibilityMode:= wdWord2003);

works fine, without the Save As dialog, but the saved file has Word 2010 format and .doc extension, which will confuse old Word versions.

So, any ideas how I can save a file in old document Word format using Word 2010 without Save As dialog popping up?

Was it helpful?

Solution

@David Heffernan: Well, writing a short demonstrating program solved my problem.

The original program opened an *.mhtml file and tried to convert it to doc format. And there I had the problem. When you create a new doc you can save it it any format without problem. That lead me to think that maybe the issue was that I saved from a non-native format to another non-native format.

So, my solution was to save it twice: first in the native format and then to the old format:

procedure SaveDocFile(WordDoc: Variant; FileName: string);
const wdFormatDocumentDefault=16;
begin
  WordDoc.ActiveWindow.View.Type := wdPrintView;
  if WordDoc.Application.Version='14.0' then
  begin
    WordDoc.SaveAs2(FileName := FileName, FileFormat := wdFormatDocumentDefault);
    WordDoc.SaveAs2(FileName := FileName, FileFormat := wdFormatDocument);
  end
  else
    WordDoc.SaveAs(FileName := FileName, FileFormat := wdFormatDocument);
end;

OTHER TIPS

List of constants for file formats:

wdFormatDocument                    =  0
wdFormatDocument97                  =  0
wdFormatDocumentDefault             = 16
wdFormatDOSText                     =  4
wdFormatDOSTextLineBreaks           =  5
wdFormatEncodedText                 =  7
wdFormatFilteredHTML                = 10
wdFormatFlatXML                     = 19
wdFormatFlatXMLMacroEnabled         = 20
wdFormatFlatXMLTemplate             = 21
wdFormatFlatXMLTemplateMacroEnabled = 22
wdFormatHTML                        =  8
wdFormatPDF                         = 17
wdFormatRTF                         =  6
wdFormatTemplate                    =  1
wdFormatTemplate97                  =  1
wdFormatText                        =  2
wdFormatTextLineBreaks              =  3
wdFormatUnicodeText                 =  7
wdFormatWebArchive                  =  9
wdFormatXML                         = 11
wdFormatXMLDocument                 = 12
wdFormatXMLDocumentMacroEnabled     = 13
wdFormatXMLTemplate                 = 14
wdFormatXMLTemplateMacroEnabled     = 15
wdFormatXPS                         = 18
wdFormatOfficeDocumentTemplate      = 23
wdFormatMediaWiki                   = 24
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top