Groups > Borland > Delphi winforms controls > Problem saving word document




Problem saving word document

Problem saving word document
Tue, 11 Jul 2006 11:57:55 +010
Hi everyone. I'm trying to alter a word document through Delphi.
I got an example from internet and i'm trying to apply it to my reality.
I set some bookmarks in my Word Document and then i'm writting after then 
through Delphi and everything is allright until
i try to save the original document (that is supposed to stay untouched as a 
template) to some other folder with another name.
When the code reaches that part ("WordApp.SaveAs(Word_doc);") the
system 
says that "Method SaveAs not supported by automation object."
If i take that part away, everything is OK; appart from the thing that want 
to create another document somewhere else.
Does this happen because i'm using office2003? Does this code only works in 
Office2000 or OfficeXP?
Can someone help please?

Here is the code

--------------------------------------------------------------------------------
----------
procedure Tfrm_mod_documento.RzBitBtn1Click(Sender: TObject);
var
marcador, R: OleVariant;
WordApp, Doc: OleVariant;
Word_Doc, path_mod, path_doc:string; //'D:\Meus Programas\Word 
Docs\doc.doc';
begin
try
WordApp := CreateOleObject('Word.Application');
except
ShowMessage('Não foi possível iniciar o MS Word!');
end;
path_mod := DM_dados.INI.ReadString('config','path_mod', '');
Word_Doc := path_mod+'oficio.doc';
// Open your Word document
try
WordApp.Documents.Open(Word_Doc);
Doc := WordApp.ActiveDocument;
except
MessageDlg('Não foi possível abrir o modelo de documento.', mtInformation, 
[mbOk], 0);
exit;
end;
// name of your bookmark
marcador := 'assunto';
// Check if bookmark exists
if Doc.Bookmarks.Exists(marcador) then
begin
R := Doc.Bookmarks.Item(marcador).Range;
// Add text at our bookmark
R.InsertAfter(DM_dados.query_modelosassunto_modelo.AsString);
// You make a text formatting like changing its color
// R.Font.Color := clRed;
end;
// name of your bookmark
marcador := 'local';
// Check if bookmark exists
if Doc.Bookmarks.Exists(marcador) then
begin
R := Doc.Bookmarks.Item(marcador).Range;
// Add text at our bookmark
R.InsertAfter(DM_dados.query_municipemorada.AsString);
end;
path_doc := DM_dados.INI.ReadString('config','path_docs', '');
Word_Doc := path_doc+'123.doc';
WordApp.SaveAs(Word_doc);
WordApp.Visible := true;
end;
--------------------------------------------------------------------------------
---------- 

Post Reply
about | contact