Delphi : Open Excel File using ShellExecute

This is a nifty code that i use whenever I do excel conversions. It helps users by seeing the excel file and not have to look for the file once the system has generated the output file

ShellExecute(Handle, 'open', 'c:\MyDocuments\MyFile.doc',nil,nil,SW_SHOWNORMAL);

In this example, the file is located inside the ‘My Documents’ folder with the file name ‘MyFile.xls’. Just in case the file name you are using is dynamic, you can enclose the variable with a PChar.

ShellExecute(Handle, 'open', PChar(varMyFilename),nil,nil,SW_SHOWNORMAL) ;

Enjoy

Coffee Cup

Leave a Reply

Your email address will not be published. Required fields are marked *