开发者

Delphi 7 and Excel 2007 Open File Error

开发者 https://www.devze.com 2023-01-04 06:06 出处:网络
I am having difficulty opening a EXCEL 2007 in Delphi 7 It works for Office 2003 and below but the wonderful people at microsoft have sent an update or something and the delphi app fell over just earl

I am having difficulty opening a EXCEL 2007 in Delphi 7 It works for Office 2003 and below but the wonderful people at microsoft have sent an update or something and the delphi app fell over just earlier this month.

  oE := GetActiveOleObject('Excel.Application');
  oE.Workbooks.Open(Filename:=sF开发者_如何学Pythonilename, UpdateLinks:=false, ReadOnly:=true); //Error

I get the following error:

'c:\Temp\Book1.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.'#$A#$A'If you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted'

Yet if I run the same command in VBA there is no problem.


I know this sounds stupid, but have you manually confirmed that the file exists at that location?

What exactly is the contents of sFileName, is it the full path or only the filename? When it is only the filename, maybe Excel can't find it because its current working directory is something else. If you are only passing the filename, try the full path instead.


the full code for the lookers :

uses ComObj; ..

procdure startExcel; 
var   
  oE:Variant; 
begin
  try 
    oE := GetActiveOleObject('Excel.Application');
  except
    oE := CreateOleObject('Excel.Application'); 
  end; 
  oE.Workbooks.Open(filename, false, false);
  oE.Visible := True; 
end;

source

0

精彩评论

暂无评论...
验证码 换一张
取 消