如何使用VBA获取活动工作簿中所有工作表的名称(或者最多三个)作为字符串返回? 对于上下文,我将在保存时使用该字符串命名工作簿。 我已经想出了如何使用输入对话框等为文件创建savename,所以这只是让VBA返回类似“[Worksheet 1 name]和[Worksheet 2 name]”的情况。
非常感谢!
How can I use VBA to get the names of all the worksheets (or alternatively a maximum of three) within the active workbook to be returned as a string? For context, I will then use the string in naming the workbook when it is saved. I have figured out how to create a savename for the file using input dialogs and so on, so it's only a case of getting VBA to return something like "[Worksheet 1 name] and [Worksheet 2 name]".
Thanks so much!
最满意答案
Option Explicit Sub namesheets() Dim wks as Worksheet, strName as String For each wks in Worksheets strName = strName & wks.Name Next End Sub你也可以谷歌“Excel VBA循环通过工作簿中的工作表”或类似的东西,并很容易地找到答案。
此外,这个问题在本网站上以某种形式提出。 请参阅链接... 循环显示工作表子集
Option Explicit Sub namesheets() Dim wks as Worksheet, strName as String For each wks in Worksheets strName = strName & wks.Name Next End SubYou can also google "Excel vba loop through worksheets in a workbook" or something to that effect and find the answer very easily.
Also, this question was asked in some form on this website. See link... Loop through subset of worksheets
更多推荐
发布评论