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

查看:60
本文介绍了如何使用 VBA 在字符串中列出工作簿中的所有工作表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 VBA 获取活动工作簿中所有工作表(或最多三个)的名称以作为字符串返回?对于上下文,我将在保存工作簿时使用该字符串命名工作簿.我已经想出了如何使用输入对话框等为文件创建保存名,所以这只是让 VBA 返回诸如[工作表 1 名称] 和 [工作表 2 名称]"之类的内容的一种情况.

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]".

非常感谢!

推荐答案

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 循环工作簿中的工作表"或类似的东西,并很容易地找到答案.

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

这篇关于如何使用 VBA 在字符串中列出工作簿中的所有工作表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆