Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel Automation setting the active page.
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00658890
Message ID:
00658895
Views:
10
>When adding a new sheet to an Excel Workbook, it is easy to make that newly add sheet the active sheet. However, I cannot make sheet 2 or 3 the active worksheet.
>
>OExcel.Worksheets.Add
>osheet = OExcel.Worksheets(4)
>osheet = OExcel.ActiveSheet
>
>** osheet is work sheet 4 which was just added.
>
>osheet = OExcel.WorkSheets(2)
>osheet = OExcel.ActiveSheet
>
>** osheet remains the last active worksheet.
>
>How can I set the active worksheet to sheet 2 and 3?

To get to the sheet I want I used the following code. It may help you. I was looking for a Sheet called 'DATA SHEET' you need only find the number of the item you are interested in.
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
Bret Hobbs

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

Click here to load this message in the networking platform