删除表前后的所有空格

发布于 2025-01-04 20:25:04 字数 539 浏览 1 评论 0原文

我正在尝试删除 Word 文档中所有表格对象之前和之后的所有空格。

这是我到目前为止的代码:

With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^p^p"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
End With

这似乎删除了一些新的换行符,但不是全部。运行此宏后,当我单击“显示所有隐藏字符”时,它仍然显示一些 |P 标签。

I am trying to remove all the whitespace before and after all table objects in my word document.

This is the code I have so far:

With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^p^p"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
End With

This seems to delete some new line breaks but not all of them. After I have run this macro, when I click to Show all hidden characters it still shows some of the |P tags.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜爱纠缠 2025-01-11 20:25:04

尝试更改

.Text = "^p^p"

.Text = Chr(32)

要找出要替换的字符,请选择文本并运行以下宏。

Sub DebugAscCode()
For i = 1 To Len(Selection.Text)
    Debug.Print Asc(Mid(Selection.Text, i))
Next i
End Sub

VBA 上的替换

Sub ReplaceAscCode()
Dim tmpArray As Variant

tmpArray = Array(7, 13, 32)

For j = LBound(tmpArray) To UBound(tmpArray)
    Selection.Text = Replace(Selection.Text, ASC(tmpArray(j)), "")
Next j

End Sub

在我的工作中使用过的

,它以这种方式完美工作,每个字符将始终由 ASC 代码[]表示

Try change

.Text = "^p^p"

to

.Text = Chr(32)

To find out which characters to replace, select your text and run the following macro.

Sub DebugAscCode()
For i = 1 To Len(Selection.Text)
    Debug.Print Asc(Mid(Selection.Text, i))
Next i
End Sub

Using replace on VBA

Sub ReplaceAscCode()
Dim tmpArray As Variant

tmpArray = Array(7, 13, 32)

For j = LBound(tmpArray) To UBound(tmpArray)
    Selection.Text = Replace(Selection.Text, ASC(tmpArray(j)), "")
Next j

End Sub

I've used in my work and it works perfectly this way, each character will always be represented by an ASC code

[]'s

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文