Vba 写长记事本
我正在尝试使用Excel中的VBA编写注释。如果评论足够短,它就可以正常工作,但是如果评论太长,它就不会再写评论了。在下面的示例中,如果我在最后一个省略号之后剪切注释,它会起作用。那个问题有什么解决办法吗Vba 写长记事本,vba,excel,Vba,Excel,我正在尝试使用Excel中的VBA编写注释。如果评论足够短,它就可以正常工作,但是如果评论太长,它就不会再写评论了。在下面的示例中,如果我在最后一个省略号之后剪切注释,它会起作用。那个问题有什么解决办法吗 Sub longComment() Cells(1, 3).NoteText Text:="Hello, I am a very long comment. Why can't I be written as a comment? It seems there is something ver
Sub longComment()
Cells(1, 3).NoteText Text:="Hello, I am a very long comment. Why can't I be written as a comment? It seems there is something very strange happening! Does anyone know what's wrong with me? How can I avoid this problem? See what happens when I add another line ... and another one ... and one more still!"
End Sub
若要添加包含255个以上字符的注释,请使用此方法一次指定前255个字符,然后再次使用此方法附加注释的其余部分(一次不超过255个字符)
这是我设法得到的:
Sub allWeNeedIsLongComment()
Dim commentToBeAdded As String
Dim commentSigns As Long
Dim cnt As Long
Dim addToFixTheLoop As Long
commentToBeAdded = "Here is FatBox Slim...." & vbCrLf & _
"1. Push the tempo! Push the tempo!Push the tempo!" & vbCrLf & _
"2. Push the tempo! Push the tempo!Push the tempo!" & vbCrLf & _
"3. Push the tempo! Push the tempo!Push the tempo!" & vbCrLf & _
"4. Push the tempo! Push the tempo!Push the tempo!" & vbCrLf & _
"5. Push the tempo! Push the tempo!Push the tempo!" & vbCrLf & _
"6. Push the tempo! Push the tempo!Push the tempo!" & vbCrLf & _
"7. Push the tempo! Push the tempo!Push the tempo!" & vbCrLf & _
"8. Push the tempo! Push the tempo!Push the tempo!" & vbCrLf & _
"9. Push the tempo! Push the tempo!Push the tempo!" & vbCrLf & _
"10. Push the tempo! Push the tempo!Push the tempo!" & vbCrLf & _
"Oh push the tempo!"
commentSigns = Len(commentToBeAdded)
If Not Range("C3").Comment Is Nothing Then Range("C3").Comment.Delete
addToFixTheLoop = commentSigns Mod 255 + 1
For cnt = 1 To (commentSigns + addToFixTheLoop) Step 255
If cnt = 1 Then
Range("C3").NoteText Text:=Mid(commentToBeAdded, cnt, 255)
Else
Range("C3").NoteText Text:=Mid(commentToBeAdded, cnt, 255), Start:=cnt
End If
Next cnt
End Sub
这就是它的样子:
或者您可以简单地使用
.Comment
而不关心循环等。您可以直接使用Comment对象,而不是使用NoteText
方法,其Text
方法没有令人讨厌的255个字符限制:
Sub test()
If Range("A1").Comment Is Nothing Then Range("A1").AddComment
Range("A1").Comment.Text String(10000, "*")
End Sub
你真的破坏了我的乐趣!:)