提问人:VBA Beginner 提问时间:10/14/2023 最后编辑:GSergVBA Beginner 更新时间:10/14/2023 访问量:69
2010 年至 2016 年间的 VBA 问题+
VBA issue between 2010 and 2016+
问:
我们不得不使用旧版 2010 版的 Excel 来运行一些旧的宏。有人可以告诉我这个宏有什么问题,它在 2010 版本中运行良好,但在 2016 版本中运行良好?我在下面以粗体显示的行中收到不匹配类型错误。我猜这是语法的变化,但我刚刚参加的 1700 美元的 Excel VBA 课程仍然没有回答我的问题。谢谢
Private Function GetDates() As Variant
Dim strSQL As String
Dim rs As New ADODB.Recordset
Dim lstDates() As Date
strSQL = " SELECT DISTINCT(DATE) " & _
" FROM [" & EXTRACTED_FILENAME & "$] "
Call GetResultSet(rs, cn, strSQL)
If (rs.RecordCount > 0) Then
ReDim lstDates(rs.RecordCount - 1) ' <== Error here
Do While (Not rs.EOF)
lstDates(rs.AbsolutePosition - 1) = CDate(rs.Fields(0))
rs.MoveNext
Loop
End If
GetDates = lstDates
End Function
这只是一个非常大的提取宏的一个函数,但这是停止整个宏的第一个问题。
答: 暂无答案
评论
rs.RecordCount
rs.GetRows
If (rs.RecordCount > 0) Then
ReDim lstDates(rs.RecordCount - 1)