参考我之前的问题: Loop through comments
当我使用specialcells循环注释时,一些迭代会多次发生。即对于下面的代码,一些包含注释(rngTemp.Value
)的单元格最多被修改三次(即该数字被添加三次到单元格值):
On Error Resume Next
Set rngComment = myTemplate.Sheets("Seite 1").Range("B14:T35").SpecialCells(xlCellTypeComments)
On Error GoTo 0
If rngComment Is Nothing Then
'Do nothing
Else
i = 1
For Each rngTemp In rngComment
If rngTemp.Comment Is Nothing Then
'do nothing change the if then else
Else
MsgBox rngTemp.value
rngTemp.value = rngTemp.value & CStr(i)
rngTemp.Characters(Start:=Len(rngTemp.value), Length:=1).Font.Superscript = True
footnote = footnote & CStr(i) & ". " & rngTemp.Comment.Text & "; "
i = i + 1
End If
Next
footnotespage1 = footnote
End If
您是否知道该错误并知道如何修复或解决它?
答案 0 :(得分:0)
将代码更改为以下内容: -
If rngTemp.Comment Is Nothing Then
'do nothing change the if then else
Else
If rngTemp.Characters(Start:=Len(rngTemp.value), Length:=1).Font.Superscript <> True Then
MsgBox rngTemp.value
rngTemp.value = rngTemp.value & CStr(i)
rngTemp.Characters(Start:=Len(rngTemp.value), Length:=1).Font.Superscript = True
footnote = footnote & CStr(i) & ". " & rngTemp.Comment.Text & "; "
i = i + 1
End If
End If
如果它以上标结尾,则根本不会这样做。