我想打开指定的word文档!(50分)

  • 主题发起人 主题发起人 yanjingdudu
  • 开始时间 开始时间
Y

yanjingdudu

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button4Click(Sender: TObject);
var
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format: OleVariant;
begin
if not dlgOpen.Execute then
Exit;
//打开文档//
FileName := dlgOpen.FileName;
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument :='';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;
///
WordApplication.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format );
/////上面这句程序WordApplication.Documents.Open()的用法总是出错,not enough actual parameters.//请各位大侠指点一下.谢谢!
ItemIndex := 1;
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
end;
/////上面这句程序WordApplication.Documents.Open()的用法总是出错,not enough actual parameters.//请各位大侠指点一下.谢谢!
/////上面这句程序WordApplication.Documents.Open()的用法总是出错,not enough actual parameters.//请各位大侠指点一下.谢谢!
/////上面这句程序WordApplication.Documents.Open()的用法总是出错,not enough actual parameters.//请各位大侠指点一下.谢谢!
 
注意office的版本差异,录个宏再数一数参数个数,不知道参数的意思可直接逗掉。
 
WordApplication.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format );
/////上面这句程序WordApplication.Documents.Open()的用法总是出错,not enough actual parameters.//请各位大侠指点一下.谢谢!
==============================================
楼主你最好不要用这种方法,很容易出错。我给你个打开WORD文档的函数吧。
procedure TForm1.openword(wcname: string;var docapp,wdoc: variant;Visible: boolean);
var i: integer;
begin

try
docapp:=GetActiveOleObject('Word.Application');
except

try
docapp:=CreateOleObject('Word.Application');
except
showmessage('没有安装Word软件或文件错误!');
exit;
end;
end;

for i:=1 to docapp.Documents.Count do
if uppercase(docapp.Documents.item(i).path+'/'+docapp.Documents.item(i).name) = uppercase(wcname) then
begin
showmessage('该文件已打开!');
docapp.Visible:=Visible;
exit;
end;


try
wdoc:=docapp.Documents.open(filename:=wcname);
docapp.Visible:=Visible;
except

end;
end;
在事件中调用:
var
WordApp,wdoc: Variant;
openword('你要打开文档的路径和文件名称', wordapp,wdoc,true);

够详细了吧。
 
后退
顶部