如何在工作表名称中搜索字符串? [英] How to search a string in a sheetname?
问题描述
我正尝试使用For Each循环在工作簿的所有工作表名称中搜索特定字符串:
I am trying to search a particular string in all sheet names of a workbook using For each loop as follows:
For Each Sheet In ActiveWorkbook.Sheets
Name = ActiveSheet.Name
Next Sheet
但是我无法使用上面的代码来获得所有工作表名称,因为它只会卡住一个工作表名称.
But i am not able to get all the sheet names using above code as it gets stuck up only one sheet name.
获得工作表名称后,我想在工作表名称中搜索一个特定的字符串.因此,如果有人可以帮助我在所有工作表中搜索字符串,那将是非常不错的.
After getting the sheet name i want to search a particular string in the sheet name So it would be great if any one can help me in searching a string in all sheets.
推荐答案
For Each sheet In ActiveWorkbook.Sheets
If sheet.Name Like "*" & strSearch & "*" Then
Debug.Print "Found! " & sheet.Name
End If
Next
您遍历所有工作表,但始终在循环中使用 ActiveSheet.Name
.要搜索模式,可以将 Like
与 *
通配符一起使用.
You iterate over all sheets, but you always use ActiveSheet.Name
in your loop.
To search for a pattern, you can use Like
with the *
wildcard.
这篇关于如何在工作表名称中搜索字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!