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:
00658905
Views:
12
>>>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
>>
>>
>
>I need to active a specific sheet. I am attempting to select a range of cells which only appears to work on the active sheet. I can access cells on any sheet without making that sheet the active sheet.

The Macro recorder shows the following:

Sheets("4027").Select

So I would try:
loExcel = CREATEOBJECT("Excel.Application")
loWorkBook = loExcel.Workbooks.OPEN('L:\vf\pss\Metrics\FY 1999 NONSM.xls')
loSheets = loWorkBook.Sheets(2)
loSheets.Select
Where 2 is the number of the sheet you want active.
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