Kbase 18787: ActiveX - How to Run a Macro in Excel or Word
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  4/17/2007 |
|
Status: Verified
GOAL:
How to run a macro in Excel
GOAL:
How to run Microsoft Office macros from 4GL
GOAL:
How to run a Microsoft Excel macro from 4GL?
FIX:
The following 4GL procedure opens an existing Microsoft Excel spreadsheet, ("C:\WRK91E\MyExcelSheet.xls"), and runs an Excel Macro, ("myExcelMacro"), that was previously saved in it:
DEFINE VARIABLE chExcelApplication AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chExcelWorkbook AS COM-HANDLE NO-UNDO.
/* Initialize Excel, File and Title Lists */
CREATE "Excel.Application" chExcelApplication.
/* Open the spreadsheet where the EXCEL Macro is saved */
chExcelWorkbook = chExcelApplication:Workbooks:Open("C:\WRK91E\MyExcelSheet.xls").
/* Run the EXCEL Macro by using it's name. */
chExcelApplication:RUN("myExcelMacro").
/* Confirm the Macro ran as desired by examining Spreadsheet */
chExcelApplication:Visible = true.
/* Cleanup by releasing all objects */
RELEASE OBJECT chExcelWorkbook NO-ERROR.
RELEASE OBJECT chExcelApplication NO-ERROR.