0

我对 VBA 很陌生,并试图调试以下代码。我不断收到->“运行时错误'13':类型不匹配”。当我调试时,“For Each ws In ActiveWorkbook.Worksheets”行以黄色突出显示。我只是想创建一个消息框,为我提供工作簿中所有工作表的名称列表。任何帮助是极大的赞赏!

Sub ListStates()
Dim ws As Worksheets
Dim message As String
message = "Here is a list of states:"
For Each ws In ActiveWorkbook.Worksheets
    message = message & vbCrLf & "ws.Name"
Next
MsgBox message, vbInformation, "State list"

结束子

4

2 回答 2

1

换行

Dim ws As Worksheets

Dim ws As Worksheet

Worksheets 对象是 Worksheet 对象的集合。Worksheet你正试图循环每一个Worksheets

于 2013-10-19T06:31:39.333 回答
0

此外,删除引号括起来 ws.Name - 行应该是:

message = message & vbCrLf & ws.Name
于 2013-10-20T07:16:26.890 回答