我正在尝试将用户窗体列表框内容导出到新工作簿。
我在代码中注释时遇到了错误。
Private Sub ExportListBoxContents_Click()
Dim xlApp As Excel.Application
Dim xlsh As Excel.Worksheet
Dim i As Integer
Dim j As Integer
Set xlApp = New Excel.Application
xlApp.Workbooks.Add
Set xlsh = xlApp.Workbooks(1).Worksheets(1)
For j = 1 To ListBox1.ListCount
For i = 0 To ListBox1.ColumnCount
xlsh.Cells(j, i).Value = ListBox1.List(j - 1, i) '<----Object defined error
Next i
Next j
xlApp.Visible = True
Set xlsh = Nothing
Set xlApp = Nothing
End Sub
答案 0 :(得分:0)
好了,经过几个小时的搜索,我设法解决了这个问题。
我要做的就是修改以下内容:
xlsh.Cells(j, i).Value = ListBox1.List(j - 1, i)
对此:
xlsh.Cells(j , i).Value = ListBox1.Column(j - 1, i - 1)