I have got an application which worked fine when saving just as a .doc file. I have since tried to get it so the program will save as both .doc and .pdf, this is done using the WordXP unit.
procedure TDocCreator.CloseDocument(ASaveAs : string);
var
LFileName : OleVariant;
begin
LFileName := ASaveAs;
FDoc.SaveAs(LFileName, EmptyParam,EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
LFileName := ChangeFileExt(ASaveAs, '.pdf');
FDoc.SaveAs(LFileName,PDFFileFormat,EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
FWordApp.NormalTemplate.Saved := true;
FWordApp.Quit(True);
FWordApp.Disconnect;
end;
If I delete the second saveas the code works fine. The 'EOleException Command Failed' exception is not popping up every time a document is saved but the point in which the break occurs is when the SaveAs is for the .pdf file.
Note I only have 2 saving procedures available SaveAs(Used above) and SaveAs2000. Also I am away from a machine which can compile delphi.
If I have missed anything or need to clear anything up I will be able to respond, however I will not be able to test any code changes till Tuesday.
Thank you.
Edit: Okay the program is being remote debugged ( The machine which does all the code does not have access to office as it is on a VM). The application goes through a set of templates which get mailmerged, once done the saving process begins. So I did 2 documents (This process is done in a for loop). This worked fine. I then tried to do 5 on the third file it brought up the 'Command Failed' error. Which then doesn't close word and cancels the remaining process. When looking at LFileName its contents were '???'. This is sometimes foreign characters. Though it still manages to make the .doc file with the correct filenam. This filename is set up outside the procedure if that makes any difference 'ASaveAs'. Another thing is that the file is not being opened using any other applications. It does the whole process using the word application the program opens.