I see some reference here, but not the answer.
How can I determine the active sheet in an Excel workbook? Some way to use the VBA Application.Activesheet property.
Thanks!
I see some reference here, but not the answer.
How can I determine the active sheet in an Excel workbook? Some way to use the VBA Application.Activesheet property.
Thanks!
See if this activity is of any help.
Good question. Yeah check out the Excel Extended.
There are also some ways to get the sheet if it has a date in the name of the sheet or if it is the last sheet that was created. Using a Workbook Application variable in an Excel Scope, you can use wb.GetSheets() as an array, which you can filter by date and sort, or just grab the last sheet by doing wb.GetSheets.Last
More specifically, think of when you save and close a multi-sheet workbook. When you re-open the workbook Excel starts with the sheet you were on when you saved (the active sheet). Within an Excel Application Scope, I need to know which sheet is the active sheet upon opening the workbook, i.e., the sheet that was active when the workbooks was last saved and closed. I have tried workbook.CurrentWorksheet but I fails with a “Object reference not set to an instance of an object.”
Is it possible to change the worksheets themselves? You can add in a formula on each worksheet that references the file path of the workbook + sheet name by putting the formula
=cell("filename")
anywhere on the worksheet. Then use UiPath string manipulation to only get the sheet name
Or you can get just the sheet using the excel formula
=MID(CELL(“filename”,A1),FIND(“]”,CELL(“filename”,A1))+1,256)
this does the string manipulation within excel instead.
wb.CurrentWorksheet.Name
does that work?
EDIT: Also, make sure the workbook variable is in the Output property of the Excel scope
I’m not totally sure, but i guess you need to Set a sheet to make it work and by default i think its null.
Sorry, I tried the wb.CurrentWorksheet.Name myself and it didn’t work. I’ll let you know if I come across a way though. Best bet right now is to have a naming convention for the sheets so you can sort it or find a key word in the sheet name. Then, you can use LINQ to grab the sheet from .GetSheets