У меня проблема с надстройкой VBA в Excel 2010.
Я создал некоторый код для анализа моих данных Excel.который я превратил в Надстройку.
Однако, когда я загружаю Надстройку и запускаю, возникает ошибка.
Сообщение об ошибке гласит: runtime error 91 object variable or With block variable not set
Ошибка указывает на rowSize = ActiveSheet.Rows.Count
.
Кто-нибудь знает, как исправить эту ошибку?
Вот код,
Private Sub Workbook_Open()
Dim counter As Long
Dim rowSize As Long
Dim userId As String
Dim answers As String
Dim vals As String
Dim i As Integer
rowSize = ActiveSheet.Rows.Count
counter = 1
'Create Column
ActiveSheet.Cells(1, 7).Value = "Country"
ActiveSheet.Cells(1, 8).Value = "State"
ActiveSheet.Cells(1, 9).Value = "Age"
ActiveSheet.Cells(1, 7).Font.Bold = True
ActiveSheet.Cells(1, 8).Font.Bold = True
ActiveSheet.Cells(1, 9).Font.Bold = True
ActiveSheet.Cells(1, 7).HorizontalAlignment = xlCenter
ActiveSheet.Cells(1, 8).HorizontalAlignment = xlCenter
ActiveSheet.Cells(1, 9).HorizontalAlignment = xlCenter
ActiveSheet.Cells(1, 7).Borders().LineStyle = xlContinuous
ActiveSheet.Cells(1, 8).Borders().LineStyle = xlContinuous
ActiveSheet.Cells(1, 9).Borders().LineStyle = xlContinuous
'Set Value
Do While counter < rowSize
If ActiveSheet.Cells(counter, 1).Value = Null Then Exit Do
If ActiveSheet.Cells(counter, 4).Value = "3" Then
userId = ActiveSheet.Cells(counter, 2).Value
vals = ActiveSheet.Cells(counter, 6).Value
'MsgBox (vals)
temp = Split(vals, ",")
i = 0
Do While i < 10
targetCell = counter + i
If ActiveSheet.Cells(targetCell, 2).Value = userId Then
ActiveSheet.Cells(targetCell, 7).Value = temp(0)
ActiveSheet.Cells(targetCell, 8).Value = temp(1)
ActiveSheet.Cells(targetCell, 9).Value = temp(2)
ActiveSheet.Cells(targetCell, 7).HorizontalAlignment = xlCenter
ActiveSheet.Cells(targetCell, 8).HorizontalAlignment = xlCenter
ActiveSheet.Cells(targetCell, 9).HorizontalAlignment = xlCenter
ActiveSheet.Cells(targetCell, 7).Borders().LineStyle = xlContinuous
ActiveSheet.Cells(targetCell, 8).Borders().LineStyle = xlContinuous
ActiveSheet.Cells(targetCell, 9).Borders().LineStyle = xlContinuous
End If
i = i + 1
Loop
temp = Null
'parsing_question_1(vals, userId)
End If
counter = counter + 1
Loop
End Sub
Спасибо!