如何使用VBA列出字符串中工作簿中的所有工作表?(How can I use VBA to list all worksheets in a workbook within a string?)

编程入门 行业动态 更新时间:2024-10-25 18:34:53
如何使用VBA列出字符串中工作簿中的所有工作表?(How can I use VBA to list all worksheets in a workbook within a string?)

如何使用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 Sub

You 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

更多推荐

本文发布于:2023-08-01 17:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1361421.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工作   字符串   如何使用   VBA   string

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!