How can I use VBA to list all worksheets in a workbook within a string?

空扰寡人 提交于 2019-11-28 08:15:05

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/10654797/how-can-i-use-vba-to-list-all-worksheets-in-a-workbook-within-a-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!