Excel VBA基于工作表名称在单元格上创建下拉列表

Excel VBA基于工作表名称在单元格上创建下拉列表,excel,vba,Excel,Vba,我想创建一个基于工作表名称的下拉列表 Worksheets("MainSheet").Range("A1").Select With Selection.Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:= ***WorkSheetnames*** .IgnoreBlank = True

我想创建一个基于工作表名称的下拉列表

Worksheets("MainSheet").Range("A1").Select

With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:= ***WorkSheetnames***
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With
所以,
***工作表名***
在哪里,我想把所有工作表名都放在哪里

也许有点

for i = 1 to application.sheets.count 
'Store data into array?
Names = sheets(i).name
next

我怎样才能在不添加工作表或其他东西的情况下做到这一点呢?

您已经接近目标了

在代码添加之前

Dim Shts As String
    For i = 1 To Sheets.Count
        Shts = Shts & ThisWorkbook.Sheets(i).Name & ","
    Next
    Shts = Left(Shts, Len(Shts) - 1)
然后在验证范围内做出

Formula1:=Shts