2
在模塊:運行時錯誤91個初始化陣列
Option Explicit
Sub sortLoggingEntrys()
Dim entrys As entrys
entrys.initialize (ActiveDocument.Tables.Count)
Dim tableIndex As Integer
Dim i As Integer
Dim j As Integer
For i = 1 To ActiveDocument.Paragraphs.Count
If InStr(ActiveDocument.Paragraphs(i), "text over table") Then
'Check if table is in next 3 paragraphs
For j = i To (i + 3)
If ActiveDocument.Paragraphs(j).Range.Information(wdWithInTable) = True Then
tableIndex = ActiveDocument.Range(0, Selection.Paragraphs(1).Range.End).Tables.Count
entrys.add DateValue(Left(ActiveDocument.Paragraphs(i), 10)), ActiveDocument.Tables(tableIndex + 1)
Exit For
End If
Next
End If
Next
End Sub
在類模塊:
Option Explicit
Dim mdate() As Date
Dim mtable() As Table
Dim index As Integer
Public Sub initialize(arraySize As Integer)
ReDim mdate(arraySize)
ReDim mtable(arraySize)
index = 1
End Sub
Public Function getDate(ByVal ix As Integer) As Date
Set getDate = mdate(ix)
End Function
Public Function getTable(ByVal ix As Integer) As Table
Set getTable = mtable(ix)
End Function
Sub add(ByVal dat As Date, ByVal tabl As Table)
mdate(index) = dat
mtable(index) = tabl
index = index + 1
End Sub
這是在字使我的第一VBA腳本。我得到運行時錯誤91.在調試模式中,我發現錯誤發生在初始化過程中。是否有可能在調試模式下跳入類模塊?我無法弄清楚如何跳進程序。我也不知道爲什麼發生錯誤。谷歌無法幫助我,希望你能。