HOWTO: Select Cells in Excel by Using OLE Automation

Article translations Article translations
Article ID: 139051 - View products that this article applies to.
This article was previously published under Q139051
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page


This article shows by example how to use OLE Automation programmatically to create a Microsoft Excel worksheet, and select a range of cells.


Step-by-Step Example

  1. In Visual FoxPro, create and run a program (.prg file) that contains the following code:
          * Start of program code
          MyF3 = ON("KEY","F3")
          ON KEY LABEL F3 DO getout
          oleWorkBook = getobject("C:\BOOK1.XLS")
          WITH oleWorkBook.Application
             .Visible = .t.
             .Windows(1).Visible = .t.
             *Selects cells A1:D5, then makes cell D1 the active cell.
          READ EVENTS
          PROCEDURE getout
          Clear EVENTS
          ON KEY LABEL F3 &MyF3
          * End of program code
  2. After Microsoft Excel starts, cells A1 through D5 should be selected.
  3. Switch back to Visual FoxPro, and press the F3 key to terminate Microsoft Excel.


Article ID: 139051 - Last Review: February 21, 2014 - Revision: 2.2
  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 6.0 Professional Edition
kbnosurvey kbarchive kbautomation kbcode kbhowto kbinterop KB139051

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from