【发布时间】:2014-10-01 13:53:26
【问题描述】:
我正在使用 Excel 工作簿中的几个 VBA For Each 循环,由于某种原因,在我的循环达到 32,766 行后出现运行时错误。我认为这是一个 Int/Long 类型错误,但我似乎无法弄清楚如何解决它。这是我当前的代码:
' Add Play Call hyperlinks
Dim Rng As Range, Cell As Range
Dim FileName As String
Dim Bureau As String
Dim CopiedFilesDirectory As String
Dim AudioFilePath As String
lastRow = Sheets("CallLog").Range("I" & Rows.Count).End(xlUp).Row
Set Rng = Sheets("CallLog").Range("I" & firstRow & ":I" & lastRow)
For Each Cell In Rng
FileName = Range("I" & Cell.Row).Value
MatterNumber = Replace(Range("K" & Cell.Row).Value, "/", "-")
ContactUsername = Range("M" & Cell.Row).Value
Bureau = Range("N" & Cell.Row).Value
CopiedFilesDirectory = ImportCallsUserForm.CopyFilesDirectoryTextBox.Value
AudioFilePath = CopiedFilesDirectory & Bureau & "\" & ContactUsername & "\" & MatterNumber & "\" & FileName & ".flac"
With Worksheets("CallLog")
.Hyperlinks.Add Anchor:=.Range("S" & Cell.Row), _
Address:=AudioFilePath, _
ScreenTip:="Click to play call", _
TextToDisplay:="Play Call"
.Hyperlinks.Add Anchor:=.Range("T" & Cell.Row), _
Address:="", _
ScreenTip:="Click to write a summary", _
TextToDisplay:="Write Call Summary"
End With
Next Cell
由于我正在使用范围,我认为可能存在一种特殊类型的变量用于 Int Ranges 与 Long Ranges,但经过广泛的在线研究后我找不到任何东西。
我们总是感谢任何帮助,我很乐意帮助澄清任何不清楚的地方。
【问题讨论】: