|
这是你窗体内原来的代码:
Private Sub UserForm_Initialize()
Dim wb As Workbook
Dim br(), cc&
cc = Application.Workbooks.Count - 1
If cc = 0 Then MsgBox "没有打开需要写入数据的文件!": Unload Me: Exit Sub
ReDim br(1 To cc, 1 To 1)
For Each wb In Workbooks
If wb.Name <> ThisWorkbook.Name Then 'And InStr(wb.Name, "数据源") = 0 Then
n = n + 1
br(n, 1) = wb.Name
End If
Next wb
ListBox1.List = br
End Sub
事件改一下,变成下面(就改个事件,内容不变,功能也基本不变):
Private Sub UserForm_Activate()
Dim wb As Workbook
Dim br(), cc&
cc = Application.Workbooks.Count - 1
If cc = 0 Then MsgBox "没有打开需要写入数据的文件!": Unload Me: Exit Sub
ReDim br(1 To cc, 1 To 1)
For Each wb In Workbooks
If wb.Name <> ThisWorkbook.Name Then 'And InStr(wb.Name, "数据源") = 0 Then
n = n + 1
br(n, 1) = wb.Name
End If
Next wb
ListBox1.List = br
End Sub
|
|