Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run an Excel Macro in Delphi

Status
Not open for further replies.

MARTINRODDY

Programmer
Apr 3, 2001
30
US
How hard is it to run an Excel macro through a Delphi program. I think an OLE excel object should be used ??? Then there is some command to run the macro ???? I appreciate any advice.

Thanks
Martin.
 
There are a couple of ways to execute Excel from Delphi. Here's one way: (the excelapp.Run('MacroName') is the command to run a macro). excelapp and excelsht are declared as variants.

excelapp:= CreateOleObject('Excel.Application');
excelapp.Visible := False;
excelapp.Workbooks.Open('O:\JMS\ProofHours.xls');
excelsht := excelapp.WorkSheets.Item['Data'];
excelsht.Activate;
excelsht.Range[excelsht.Cells.Item[2, 1], excelsht.Cells.Item[(personcount + 1), 5]].Value := ProcessList;
excelapp.Run('Process_Report');
Sleep(2000);
excelapp.Worksheets.Item['Report1'].printout;
excelapp.displayalerts := False;
excelapp.quit;

Good luck!
Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Check out:
How to export data to Excel
faq102-1562 in the FAQ Area Steven van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top