0

我正在寻找一种使用 VBA 删除评论中的空行的方法。我有一个 Excel 文件,其中包含大量损坏的注释,包含空行,并且不能逐个浏览它们。

我还没有确定在评论中编辑行的命令,也不知道从哪里开始,所以我没有任何代码给你们看。但我的想法是:

For Each comment In ActiveSheet.Comments
    "REMOVE EMPTY ROWS" <-- What to put here?
Next comment

无论如何,希望你能帮助我!

编辑:我所有的空行都在评论的末尾,如下所示:

在此处输入图像描述

4

2 回答 2

3

我找到了答案。似乎它不是空行,它只是以某种方式更改的评论的大小。所以这段代码修复了它:

Sub Comments_AutoSize()

Dim MyComments As Comment
Dim lArea As Long
For Each MyComments In ActiveSheet.Comments
  With MyComments
    .Shape.TextFrame.AutoSize = True
    If .Shape.Width > 300 Then
      lArea = .Shape.Width * .Shape.Height
      .Shape.Width = 200
      .Shape.Height = (lArea / 200) * 1.1
    End If
  End With
Next
End Sub
于 2013-09-26T08:20:58.883 回答
1

假设您的评论看起来像这样

在此处输入图像描述

你可以试试这个

Sub RemoveEmptyLinesInComments()

    Dim c As Comment
    For Each c In ActiveSheet.Comments
        c.Text Text:=Replace(c.Text, vbLf, Chr(32))
    Next c

End Sub

实现

在此处输入图像描述

更新

好的,在您编辑问题并使用提供的详细信息更改含义后,我想出了另一个代码作为解决方案。尝试

Sub RemoveEmptiesFromComments()

    Dim c As Comment
    For Each c In ActiveSheet.Comments
        Dim v As Variant
        v = Split(c.Text, Chr(32))
        Dim i As Long, s As String
        For i = LBound(v) To UBound(v) - 1
            s = s & Chr(32) & v(i)
        Next i
        Dim rng As Range
        Set rng = c.Parent
        c.Delete
        rng.AddComment Text:=s
        rng.Comment.Shape.TextFrame.AutoSize = True
    Next c

End Sub
于 2013-09-26T08:03:17.383 回答