MS Word表-宏以查找包含特定文本的行,然后将整行移至表中的最后一行 [英] MS Word table -macro to find row containing specific text then move entire row to last row in the table

查看:449
本文介绍了MS Word表-宏以查找包含特定文本的行,然后将整行移至表中的最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图创建一个宏,该宏将搜索MS Word表,找到一个特定的词,然后将整行移到表的底部,然后重复该词的下一个出现.

Looking to create a macro that will search down MS Word table, find a specific word, then move that entire row to the bottom of the table, then repeat for the next occurrence of that word.

推荐答案

@vbaexpress提供的规范与您在此处给出的规范有些不同.假设vbaexpress规格正确,请尝试:

The specs you've given @ vbaexpress are somewhat different to what you gave here. Assuming the vbaexpress specs are correct, try:

Sub Demo()
Application.ScreenUpdating = False
Dim TblRng As Range, TmpRng As Range
With ActiveDocument.Tables(1)
  Set TblRng = .Range: Set TmpRng = .Range
  With .Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = "DENIED"
      .Replacement.Text = ""
      .Forward = True
      .Format = False
      .Wrap = wdFindStop
      .MatchCase = True
      .MatchWholeWord = True
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Execute
    End With
    Do While .Find.Found
      If .InRange(TblRng) Then
        TmpRng.Collapse wdCollapseEnd
        TmpRng.FormattedText = .Rows(1).Range.FormattedText
        .Rows(1).Delete
      End If
      .Find.Execute
    Loop
  End With
  If .Rows.Count > TblRng.Rows.Count Then
    .Split .Rows(TblRng.Rows.Count + 1)
  End If
End With
Application.ScreenUpdating = True
End Sub

注意:以上代码假定您仅在处理文档中的第一个表;如果它是另一个表,请更改.Tables(1)中的1以适合.

Note: the above code assumes you're processing just the first table in the document; if it's a different table, change the 1 in .Tables(1) to suit.

这篇关于MS Word表-宏以查找包含特定文本的行,然后将整行移至表中的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆