AutoXL.exe, included on the sample disk (in the SAMPLE\AUTOXL directory), uses the dispargs functions to implement a more complex OLE Automation Controller. AutoXL uses Microsoft Excel to create a pie chart. It starts Microsoft Excel, adds a new workbook, inserts data into the first worksheet in the workbook, and then uses the ChartWizard method to create a pie chart. The following Visual Basic code shows the equivalent work:
Set wb = Application.Workbooks.Add(template := xlWorksheet)
Set ws = wb.Worksheets(1)
ws.Range("A1:D1").Value = Array("North", "South", "East", "West")
ws.Range("A2") = 5.2
ws.Range("B2") = 10
ws.Range("C2") = 8
ws.Range("D2") = 20
Set sourceRange = ws.Range("A1:D2")
Set crt = wb.Charts.Add
crt.ChartWizard source := sourceRange, gallery := xl3DPie, _
format := 7, plotBy := xlRows, categoryLabels := 1, _
seriesLabels := 0, hasLegend := 2, title := "Sales Percentages"
wb.Saved = True
' So that Excel won't ask whether to save this document on close.