 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Mark Lemon Guest
|
Posted: Wed Jul 26, 2006 3:21 pm Post subject: Word SaveAs |
|
|
Hello
Delphi 7 with update applied.
Imported Type Library... Microsoft Word 10.0 Object Library (Version 8.2)
Generate Component Wrapper unchecked ... Create Unit to provide Word_TLB.pas
Sample form below to highlight problem.
When calling
WordDoc.SaveAs(...
in the code below I get a "Type mismatch" error. I thought I would only need
OLEVariant type parameters. I have tried putting "varFalse" in some of the
parameters too.
I have decided not to use the components in Delphi because when calling
wordBookmark.Range.InsertAfter(varInsertText);
I get a "Server threw an exception error" on some PCs even though everybody
is using Windows XP and XP Office. The type library approach (early binding)
erradicates this error.
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Word_TLB;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
varTemplateFilename,
varFalse,
varBookmarkName,
varInsertText,
varFileName,
varFormat,
varEmptyString,
EmptyParam: OLEVariant;
wordApp: Word_TLB.WordApplication;
wordDoc: Word_TLB.WordDocument;
wordBookmark: Word_TLB.Bookmark;
begin
varTemplateFilename := 'c:\TEMP\TestWord2\Letter.dot';
varFalse := False;
varBookmarkName := 'BMFullName';
varInsertText := 'TEST INSERT TEXT';
varFormat := wdFormatDocument;
varEmptyString := '';
wordApp := Word_TLB.CoWordApplication.Create;
varFileName := 'C:\TEMP\TestWord2\Test' + StringReplace(DateToStr(Date),
'/', '_', [rfReplaceAll]);
try
wordDoc := wordApp.Documents.Add(varTemplateFileName, varFalse,
EmptyParam, varFalse);
wordDoc.Activate;
wordDoc.SaveAs(varFileName, varFormat,
EmptyParam, EmptyParam,
EmptyParam, EmptyParam,
EmptyParam, EmptyParam,
EmptyParam, EmptyParam,
EmptyParam, EmptyParam,
EmptyParam, EmptyParam,
EmptyParam, EmptyParam);
wordBookmark := wordDoc.Bookmarks.Item(varBookmarkName);
wordBookmark.Range.InsertAfter(varInsertText);
finally
WordApp.Visible := True;
WordApp.WindowState := wdWindowStateMaximize;
WordApp.Activate;
end;
end;
end.
Thanks in advance.
Mark Lemon
Developer
Monodraught Limited
www.monodraught.com |
|
| Back to top |
|
 |
Deborah Pate (TeamB) Guest
|
Posted: Wed Jul 26, 2006 5:30 pm Post subject: Re: Word SaveAs |
|
|
<<Mark Lemon:
EmptyParam: OLEVariant;
Remove this declaration and add Variants to your uses
clause. EmptyParam is declared and created for you there -
it's not the same thing as an unallocated variant.
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Jul 26, 2006 7:04 pm Post subject: Re: Word SaveAs |
|
|
Thanks Deborah.
I've obviously been a plonker.
Simple point overlooked. Must be the heat and humidity in the UK here
at the moment.
Regards
Mark
Deborah Pate (TeamB) wrote:
| Quote: | Mark Lemon:
EmptyParam: OLEVariant;
Remove this declaration and add Variants to your uses
clause. EmptyParam is declared and created for you there -
it's not the same thing as an unallocated variant.
--
Deborah Pate (TeamB) http://delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|