Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Launch Excel, and run a macro automatically
Message
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
00491575
Message ID:
00491803
Views:
11
>I have an application that tracks the net sales for a Pizza company. They need an easy way to view graphs of net sales. I have written the front end were they can select to 4 series of data. I use the data to create an Excel file using "copy to filename type xls". Without going into all of the details, I would like to have a "View graph" button on the VFP form that starts excel, opens the worksheek and runs the macro that creates the chart. All I want the user to do is click the button on the form. Any suggestions on the best way to do this. I already have the Excel files completed.

Some code I use to set up Excel and then run a macro I have in the spreadsheet
loExcel = CreateObject("Excel.Application")
loWorkBook = loExcel.Workbooks.Open(lcExcelFileFullPath)
* Get a reference to the Sheets in the Excel spreadsheet
loSheets = loWorkbook.Sheets
* Now that we have a sheets collection lets
* get the one we want to update
FOR i = 1 to loSheets.Count
  loSheet = loSheets.Item(i)
  IF UPPER(loSheet.Name) = 'DATA SHEET'
    * We found what we want to work with
    EXIT
  ENDIF
ENDFOR

* IF there was not empty cell then we have to move columns over to create one
* and to delete the first column (This drops off the oldest and adds a new one)
IF NOT llFoundCell
  * What we are doing here is calling a macro to do our work
  * which is easier than coding it here
  loExcel.Run("AddNewMetricColumn")
  loExcel.Run("DeleteFirstMetricColumn")
  * The starting column will be the last one
  lcStartColumn = 'Q'
ENDIF
Bret Hobbs

"We'd have been called juvenile delinquents only our neighborhood couldn't afford a sociologist." Bob Hope
Previous
Reply
Map
View

Click here to load this message in the networking platform