当宏退出For循环时,出现类型不匹配错误。我不知道为什么,但希望得到任何帮助。我曾尝试寻找这个问题,但没有任何建议适用于我的情况。退出循环的Excel宏类型不匹配错误
Option Explicit
Dim MODULE_NAME() As String
Dim Counter As Long
Dim i As Long
1210 For Counter = i To CLng(i + CLng(CLng(UBound(MODULE_NAME)) Mod 127))
1220 Call MacroLineNum(Counter, MODULE_NAME, TotalLines)
1230 If Counter Mod UpdateFreq = 0 Then
1240 '**Save the file
1250 With gloMacroWorkbook
1260 If Not .ReadOnly Then
1270 .Save
1280 Else
1290 .Saved = False
1300 End If
1310 End With
1320 LockWindowUpdate 0&
1330 '-------------------------------------------------------------------------------------------------
1340 ' Update the status bar.
1350 '-------------------------------------------------------------------------------------------------
1360 Call subStatusBarUpdater("Still updating the line numbers in the modules. " & Counter & " of " & UBound(MODULE_NAME) & " processed....")
1370 If VBEHwnd Then
1380 LockWindowUpdate VBEHwnd
1390 End If
1400 End If
1410 If Counter = UBound(MODULE_NAME) Then
1420 MsgBox "Exiting for loop."
1430 End If
1440 Next Counter
1450 MsgBox "Saving file"
我的代码行达到1420,而不是1450线甚至我加入类型转换功能“CLng函数”到1210,但似乎没有任何帮助。在1420和1450行之间,我总是得到'类型不匹配'的错误,没有详细说明在哪里以及为什么。
MODULE_NAME()数组是一个包含159个字符串条目的动态数组。任何帮助将不胜感激。
'MacroLineNum'做什么? – Comintern
@ Mat'sMug它跳跃10,所以它是145 :) –
@AA它似乎你不是退出'For'循环,在行1430之后(在Next Counter之前)添加一个'MsgBox'并且写入'MsgBox “计数器是:”&计数器“ –