ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   determine the active workbook containing a specific sheet (https://www.excelbanter.com/excel-programming/341465-determine-active-workbook-containing-specific-sheet.html)

Valeria

determine the active workbook containing a specific sheet
 
Dear experts,
I am trying to determine within my open workbooks the one that contains the
sheet "Instructions", workbook that I would like to activate.
My code (not working!) is the following:

i = 0
Do
i = i + 1
Loop Until IsError(Workbooks(i).Worksheets("Instructions")) = False
Workbooks(i).Activate
WBReport = Workbooks(i).Name

Could you please help me?
Many thanks!
Best regards,

--
Valeria

K Dales[_2_]

determine the active workbook containing a specific sheet
 
Function ActivateInstructions() As String
' Will activate the worksheet "Instructions"
' Returns the name of the workbook containing the sheet "Instructions"
' Note: If there happens to be more than one workbook with a sheet called
"Instructions" this will activate and return the one opened most recently.
' If no book contains a sheet called "Instructions" function returns an
empty string

Dim WB As Workbook
ActivateInsrtuctions = ""
For Each WB In Application.Workbooks
On Error GoTo NoInstructions
WB.Worksheets("Instructions").Activate
ActivateInstructions = WB.Name
NoInstructions:
On Error GoTo 0
Next WB
End Function

--
- K Dales


"Valeria" wrote:

Dear experts,
I am trying to determine within my open workbooks the one that contains the
sheet "Instructions", workbook that I would like to activate.
My code (not working!) is the following:

i = 0
Do
i = i + 1
Loop Until IsError(Workbooks(i).Worksheets("Instructions")) = False
Workbooks(i).Activate
WBReport = Workbooks(i).Name

Could you please help me?
Many thanks!
Best regards,

--
Valeria



All times are GMT +1. The time now is 05:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com