#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    Opening Excel with File


    I'm using Delphi 4 and in trying to open Excel through my Delphi program in Windows 7, I get an exception as the program is starting... "Exception EOleSysError in module MYPROGRAM.EXE at 000979C5, Class not registered." The code works just fine in an XP environment. Think I could get some help with this please?

    Also, I'm trying to find a method of opening Excel 2007 with a particular file in Windows 7 using ShellExecute... should be easy, but I haven't found one that works yet in Windows 7; however, I've gotten ShellExecute to work properly in XP....... Thanks!

    (sample code using ShellExecute)
    procedure TMDIChild.mnuExportToExcelClick(Sender: TObject);
    var
    Filename: string;
    begin
    if OpenBOM.Execute then
    begin
    Memo3.Lines.LoadFromFile(OpenBOM.FileName);
    //Scratch.Memo1.Lines.Add('Filename = ' + OpenBOM.Filename);
    Filename := OpenBOM.Filename;
    end;

    if AboutBox.lblOS.Caption = 'Microsoft Windows XP' then
    begin
    Filename := OpenBOM.Filename;
    //test
    //Scratch.Memo1.Lines.Add('OS = XP');
    ShellExecute(Handle,'open', 'Excel.exe',
    PChar(Filename), nil, SW_SHOWNORMAL)
    end
    else if AboutBox.lblOS.Caption = 'Windows 7 Professional' then
    begin
    Filename := OpenBOM.Filename;
    ShellExecute(Handle,'open', 'C:\Program Files\Microsoft Office\Office12\Excel.exe',
    Pchar(Filename), nil, SW_SHOWNORMAL)
    end;

    end;

    (sample code using ComObj)
    procedure TMDIChild.mnuExportToExcelClick(Sender: TObject);
    var
    oExcel: Variant;

    begin
    oExcel := CreateOleObject('Excel.Application');
    oExcel.WorkBooks.Add(-4167);

    if OpenBOM.Execute then
    begin
    Memo3.Lines.LoadFromFile(OpenBOM.FileName);
    OpenFile := OpenBOM.Filename;
    end;

    oExcel.WorkBooks.Open(OpenBOM.Filename);
    oExcel.Visible:= True;

    end;
    Last edited by MikalThor; October 3rd, 2012 at 06:45 AM. Reason: added additional sample code
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    oh... OK


    I've learned how to open Excel in both XP and W7 through Delphi. On the XP platform I'm able to open a file as Excel is coming up (which is what I'm looking for); however, in W7... Excel issues a message that it can't find the "Program.xlsx" file. Is this a template that Excel is looking for? Is there a way around this? .... thanks....

IMN logo majestic logo threadwatch logo seochat tools logo