数组提供的ListBox中额外的空白行
这是驱动它的原因:
Dim wb As Workbook Dim arrList() Dim iInstances As Long iInstances = 0 For Each wb In Application.Workbooks If wb.Name <> ThisWorkbook.Name Then iInstances = iInstances + 1 ReDim Preserve arrList(iInstances) arrList(iInstances) = wb.Name End If Next With Sheets(1) .Shapes("ListBox1").Height = 136.5 .ListBox1.List = arrList End With
问题:代码在列表顶部插入一个空行(我不想要)。
尝试:
If wb.Name <> ThisWorkbook.Name Then ReDim Preserve arrList(iInstances) arrList(iInstances) = wb.Name iInstances = iInstances + 1 End If
把下面的东西放到你的模块中。
Option Base 0
您正在创build一个空索引为0的数组,因此您只需在添加工作簿后增加计数器即可:
For Each wb In Application.Workbooks If wb.Name <> ThisWorkbook.Name Then ReDim Preserve arrList(iInstances) arrList(iInstances) = wb.Name iInstances = iInstances + 1 End If Next