MdJ70
asked on
Delphi 2009 word 2007
In the uses part i have word2000 (is there a 2007 library?)
i try to open an docx document. It compiles ok, but i get type mismatch at line:
Word.Documents.Open(FileNa me,EmptyPa ram,EmptyP aram,Empty Param,Empt yParam,Emp tyParam,Em ptyParam,E mptyParam, EmptyParam ,EmptyPara m,EmptyPar am,EmptyPa ram);
what's wrong?
i try to open an docx document. It compiles ok, but i get type mismatch at line:
Word.Documents.Open(FileNa
what's wrong?
unit D2009Word2007U;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, word2000,ExtCtrls,ComObj, ActiveX;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var
Word: _Application;
AppWasRunning: boolean; // tells you if you can close Word when you've finished
Unknown: IUnknown;
Result: HResult;
FileName,EmptyParam: OleVariant;
begin
timer1.Enabled:=false;
AppWasRunning := False;
{$IFDEF VER120} // Delphi 4
Result := GetActiveObject(CLASS_Application_, nil, Unknown);
if (Result = MK_E_UNAVAILABLE) then
Word := CoApplication_.Create
{$ELSE} // Delphi 5
Result := GetActiveObject(CLASS_WordApplication, nil, Unknown);
if (Result = MK_E_UNAVAILABLE) then
Word := CoWordApplication.Create
{$ENDIF}
else begin
{ make sure no other error occurred during GetActiveObject }
OleCheck(Result);
OleCheck(Unknown.QueryInterface(_Application, Word));
AppWasRunning := True;
end;
Word.Visible := True;
FileName := 'c:\file.docx';
Word.Documents.Open(FileName,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Word Object Library is:
Office 12\MSWORD.OLB
Microsoft Office 12.0 Object Library (Office shared functionality)
office.dll
See this page which lists them all:
http://msdn.microsoft.com/en-us/library/15s06t57.aspx
HTH
Office 12\MSWORD.OLB
Microsoft Office 12.0 Object Library (Office shared functionality)
office.dll
See this page which lists them all:
http://msdn.microsoft.com/en-us/library/15s06t57.aspx
HTH
There was a similar office automation question recently... the last parameter needed to be something other than null... let me see if I can find more info on that.
In the mean time, there is a simpler way to try to tackle it. You can request the default word application. This will return the office 2007 if it is installed or office 2003 or whatever is installed. You can then call the Open with just the file name. The down side of this is that you loose the tips on the parameters. The upside is that it can make things much easier versus multiple versions you try to run against. Here is a link with some code.
http://www.swissdelphicenter.ch/torry/showcode.php?id=1691
In the mean time, there is a simpler way to try to tackle it. You can request the default word application. This will return the office 2007 if it is installed or office 2003 or whatever is installed. You can then call the Open with just the file name. The down side of this is that you loose the tips on the parameters. The upside is that it can make things much easier versus multiple versions you try to run against. Here is a link with some code.
http://www.swissdelphicenter.ch/torry/showcode.php?id=1691
ASKER
thanks
ASKER
the error seems to be in the Word.Documents.Open part....
2 questions:
1)what is the name of the office/word 2007 automation library?
(i can't seem to find it in Import component-import activeX. office 2007 is installed on my system though.)
2) what is the name of the office 2007 automation libray in the uses clause? word2007?
thanks.