就像你可以从文本文档中复制任意数量的行并在连续的行中粘贴到Excel中一样,我希望能够复制文本行并将它们粘贴到Excel中连续行的注释中。为了使它更容易,我首先将.txt文件中的注释文本行粘贴到Excel中的列中。这就是我现在正在看的内容:
Dim myClip As New DataObject
Dim myString As String
myClip.GetFromClipboard
myString = myClip.GetText
Sheet1.Range("A1").AddComment myString
但是像这样从剪贴板粘贴似乎没有达到预期的效果。有什么想法吗?
答案 0 :(得分:1)
Sub AddCommentsToSelection()
Dim myClip As New DataObject
Dim myString As String
Dim c As Range, arr, x As Integer
myClip.GetFromClipboard
myString = myClip.GetText
If Len(myString) = 0 Then Exit Sub
Set c = Selection.Cells(1)
arr = Split(myString, vbCrLf)
For x = LBound(arr) To UBound(arr)
c.AddComment arr(x)
Set c = c.Offset(1, 0)
Next x
End Sub