Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 使用宏删除重复的标题_Vba_Ms Word - Fatal编程技术网

Vba 使用宏删除重复的标题

Vba 使用宏删除重复的标题,vba,ms-word,Vba,Ms Word,我试图找到一个word宏,可以删除重复的标题以及没有内容的标题。例如,使用以下标题 3.2.3运行ID:795-REG-C1-TC003弹出窗口不工作 3.2.4运行ID:796-REG-C1-TC004搜索 3.2.5运行ID:879-REG-C1-TC005 Blabla 3.2.6运行ID:797-REG-C1-TC005 Blabla 3.2.7运行ID:799-REG-C1-TC006 ReplyTo功能 我想删除两个重复的问题(TC005 blablabla),除非这是一个已经被问

我试图找到一个word宏,可以删除重复的标题以及没有内容的标题。例如,使用以下标题

3.2.3运行ID:795-REG-C1-TC003弹出窗口不工作
3.2.4运行ID:796-REG-C1-TC004搜索
3.2.5运行ID:879-REG-C1-TC005 Blabla
3.2.6运行ID:797-REG-C1-TC005 Blabla
3.2.7运行ID:799-REG-C1-TC006 ReplyTo功能

我想删除两个重复的问题(
TC005 blablabla

,除非这是一个已经被问到和回答过的问题,否则这里不是“查找”宏的地方:通常在这里,您会发布有问题的代码并获得修复帮助。这是我的代码。我找不到常用的搜索“文本”。“TC..”后面的字符数有时会不同。。我如何动态检查它?
Sub lösch_kapitel()
Dim fundbereich As Range
Dim firstRound As Boolean
Dim counter As Integer

firstRound = True
counter = 0

Set fundbereich = ThisDocument.Content 'gesamtes aktives Dokument durchsuchen

    With fundbereich.Find
        .ClearFormatting
        .Format = True
        .Style = "Überschrift 4"
        .Text = "TC??????????????"
        .Forward = True
        .MatchCase = True
        .MatchWildcards = True
        .Wrap = wdFindStop 'nach jeder Fundstelle stoppen

        Do While fundbereich.Find.Execute = True 'wenn eine Überschrift1 gefunden wird

               If firstRound = True Then

                 pFound = fundbereich.Text
               ElseIf (firstRound = False) Then

                    If fundbereich.Text = pFound Then
                        fundbereich.Select 'gefundene Überschrift auswählen
                         'alles von der Überschrift bis zur nächsten der gleichen Ebene auswählen:
                        ThisDocument.Bookmarks("\headinglevel").Select
                        Selection.Delete
                        counter = counter + 1
                    End If
                    pFound = fundbereich.Text
               End If
               firstRound = False

        Loop

        MsgBox counter & " Kapitel gelöscht!"

    End With

ThisDocument.TablesOfContents(1).Update

End Sub