Delphi Ole Automation - save Word97-2003 file in Word 2010 without "Save As" dialog

I am 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 a save dialog and I'm not sure why. I have tried the new SaveAs2 method

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

      

but with the same result.

Surprisingly,

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

      

works fine without the Save As dialog, but the saved file is in Word 2010 format and a .doc extension, which confuses older versions of Word.

So, any ideas how I can save the file as an old Word document using Word 2010 without the Save As dialog?

+3


source to share


2 answers


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

The original program opened the * .mhtml file and tried to convert it to doc format. And there I had a problem. When you create a new document, you can save it in any format without any problem. This made me think that maybe the problem is that I saved from a non-native format to another non-native format.



So my solution was to save it twice: first in native format and then in 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;

      

+2


source


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

      

0


source







All Articles