🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.winforms.controls.using
Article #213

Problem saving word document

#213
From: Jorge Ferreira
Date: Tue, 11 Jul 2006 10:57
66 lines
3368 bytes
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;
------------------------------------------------------------------------------------------ 
Technical Details
Message-ID: <44b38400$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 1eff29,b94ad7fa6d78e70a,start
X-Google-Attributes: gid1eff29,public
X-Google-Language: ENGLISH,ASCII
Reply-To: "Jorge Ferreira" <ferreira.jorge@gmail.com>
From: "Jorge Ferreira" <ferreira.jorge@gmail.com>
Newsgroups: borland.public.delphi.winforms.controls.using
Subject: Problem saving word document
Date: Tue, 11 Jul 2006 11:57:55 +0100
Lines: 68
Organization: CMC
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 85.241.43.156
Message-ID: <44b38400$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1152615424 85.241.43.156 (11 Jul 2006 03:57:04 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail