Jump to content

How to open a workbook and activate a specific sheet


Recommended Posts

@water

Hlo folks,

I m trying to open a workbook in excel and then open a particular sheet. I don't find any way to resolve this problem. I also trying _ExcelSheetActivate() function but this will not work.

Here is my code

Local $oExcel_1= _Excel_Open()
Local $sWorkbook="C:\Users\Tushar Verma\Desktop\AUTO IT\Test.xlsx"
Local $oWorkbook = _Excel_BookOpen($oExcel_1,$sWorkbook)
_ExcelSheetActivate($oExcel_1, "Test") ; I want to open this sheet (Test) but this will not open 


WinActivate($oWorkbook)
Sleep(3000)
$read1=_Excel_RangeRead($oWorkbook,Default,"A2")

 Thanks in advance !! 

Link to comment
Share on other sites

_ExcelSheetActivate is a function of a very, very old version of AutoIt. The Excel UDF has been rewritten since and all functions renamed to _Excel_*. Some of them have been dropped.
Please see the AutoIt change history.

With activating a specific sheet you automate the Excel GUI. With the Excel UDF you use the COM interface. I suggest to not mix this two.
Use the correct UDF function for your goal and pass the sheet number or name to process as parameter.

What exactly do you want to do with the selected sheet?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

If you want to activate a worksheet you can also use the $oWorkbook.Worksheets("Sheet1").Activate to make it the active sheet.  Example below:

#include <Array.au3>
#include <Excel.au3>

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Workbook.xlsx")
;~ Activate/Navigate to worksheet "Sheet1"
;~ nb: Not required to use _Excel_RangeRead
$oWorkbook.WorkSheets("Sheet1").Activate
;~ Read range A1:B4 on Sheet1
Local $aWorkbook = _Excel_RangeRead($oWorkbook, "Sheet1", "A1:B4")
_ArrayDisplay($aWorkbook)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...