Итак, я получаю несоответствие типа в скрипте VBA документа Word, однако в редакторе нет какой-либо строки. Может ли кто-нибудь из вас дать мне подсказку что это может быть?Несоответствие типа vba на моем скрипте
Private Sub bt_run_Click()
'set months array
Dim months As Variable
months = Array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro")
With ThisDocument.Tables(0)
Do While .Rows.Count > 2
.Rows(2).Delete
Loop
'Ask for year
Dim req As String
Dim yr As Integer
req = InputBox("Insere ano.")
If IsNumeric(req) Then
yr = CInt(req)
Else
MsgBox ("Erro")
Return
End If
'get previous year last week
'TODO
'Now generate current year months
For i = 1 To 12
'get number of mondays on the month (how many weeks belong here)
Dim mondays As Integer
mondays = MondaysOnMonth(i, yr)
'now generate a line for each monday
For k = 1 To mondays
.Rows.Add
Next k
Next i
'get next year first week
'TODO
End With
End Sub
Function MondaysOnMonth(ByVal month As Integer, ByVal year As Integer) As Integer
Dim mondays As Integer
mondays = 0
Dim d As Date
Dim dtStr As String
dtStr = "1/" & month & "/" & year
d = DateValue(dtStr)
Dim days As Integer
days = dhDaysInMonth(d)
For i = 1 To days
dtStr = i & "/" & month & "/" & year
d = DateValue(dtStr)
Dim w As Integer
w = Weekday(d, vbMonday)
If w = 0 Then
mondays = mondays + 1
End If
Next i
MondaysOnMonth = mondays
End Function
Function dhDaysInMonth(Optional ByVal dtmDate As Date = 0) As Integer
' Return the number of days in the specified month.
If dtmDate = 0 Then
' Did the caller pass in a date? If not, use
' the current date.
dtmDate = Date
End If
dhDaysInMonth = DateSerial(year(dtmDate), _
month(dtmDate) + 1, 1) - _
DateSerial(year(dtmDate), month(dtmDate), 1)
End Function
Это довольно много генерирует количество строк, как есть в течение всего месяца в единственной таблице документа.
Я не очень разбираюсь во всех этих видах Visual Basic для приложений, но я предполагаю, что это какой-то тип, который компилятор не может выполнить, однако я не могу понять, что это может быть (и компилятор не дает мне необходимую помощь), так что это может быть?
Вы попробовали F8? Шаг хотя? –
Нет, но попробовал это сейчас, и это когда я назначаю Array в переменную месяцев ... Не должен ли тип Variable быть динамической переменной? –