Indexing mit Word: Makrocodes, Teil 1

Contents

Makros aus Unterkapitel 6.12

Weitere Makrocodes zu verschiedenen Themen sind in Teil 2 und Teil 3 zu finden.

Sub leeresxefeld()


‚ Makro zum Einfügen eines leeren XE-Feldes; Makro wurde aufgezeichnet und nicht nachbearbeitet; zur Makroausführung kann sich der Cursor an beliebiger Stelle im Text befinden

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:=“XE“, PreserveFormatting:=False
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=““““““
Selection.MoveLeft Unit:=wdCharacter, Count:=1
End Sub
–––––––––––––––––

Sub markierung_als_ut()


‚ Makro zum Verschieben des markierten Textes in den Untereintrag; Makro wurde aufgezeichnet und nicht nachbearbeitet; zur Makroausführung muss Text im XE-Feld markiert sein

Selection.Cut
Selection.Extend
Selection.Extend Character:=““““
Selection.EscapeKey
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=“:“
Selection.PasteAndFormat (wdFormatOriginalFormatting)
End Sub
–––––––––––––––––

Sub eintragverdoppeln()


‚ Makro zum Verdoppeln eines Eintrags; Makro wurde aufgezeichnet und nicht nachbearbeitet; zur Makroausführung muss sich der Cursor im XE-Feld befinden

Selection.Find.ClearFormatting
With Selection.Find
.Text = „^d XE“
.Replacement.Text = „“
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Copy
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdFormatOriginalFormatting)
End Sub
–––––––––––––––––

Sub ht_ut_umdrehen()


‚ Makro zum Umdrehen von HT und UT; Makro wurde aufgezeichnet und nicht nachbearbeitet; zur Makroausführung muss sich der Cursor im XE-Feld befinden

Selection.Find.ClearFormatting
With Selection.Find
.Text = „XE#“““
.Replacement.Text = „“
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Extend
Selection.Extend Character:=“:“
Selection.EscapeKey
Selection.Cut
Selection.Extend
Selection.Extend Character:=““““
Selection.EscapeKey
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=“:“
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.TypeBackspace
End Sub
–––––––––––––––––

Sub Klammern_tauschen()


‚ Makro zum Tauschen von Klammern; Makro wurde aufgezeichnet und nicht nachbearbeitet; zur Makroausführung muss sich der Cursor im XE-Feld befinden; insbesondere bei Abkürzungen zu gebrauchen

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „(„
.Replacement.Text = „“
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Extend
Selection.Extend Character:=“)“
Selection.EscapeKey
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Ex-tend:=wdExtend
Selection.Cut
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „(„
.Replacement.Text = „“
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „XE#“““
.Replacement.Text = „“
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.TypeText Text:=“ („
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „XE#“““
.Replacement.Text = „“
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „(„
.Replacement.Text = „“
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „(„
.Replacement.Text = „“
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub
–––––––––––––––––

Sub markierten_text_suchen()


‚ Makro zum Suchen von markiertem Text; kann Dokumenttext sein oder Indextext zur Suche im Index, z. B. zur Überprüfung eines Querverweises; Makro wurde aufgezeichnet, dann wurde die Variable a manuell eingebaut; zur Makroausführung muss Text markiert sein

Dim a
Selection.Font.Hidden = False
a = Selection.Text ‚variable
Selection.Find.ClearFormatting
With Selection.Find
.Text = a ‚variable wird hier eingesetzt
.Replacement.Text = „“
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
End Sub
–––––––––––––––––

Sub gehezu_naechstem_xefeld()


‚ springt zum mächsten XE-Feld; Makro wurde aufgezeichnet und nicht verändert; zur Makroausführung kann sich der Cursor an beliebiger Stelle im Text befinden

Selection.GoTo What:=wdGoToField, Which:=wdGoToNext, Count:=1,
Name:=“xe“
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Font.Reset
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
–––––––––––––––––

Sub xe_feld_hervorheben()


‚ Makro zum Hervorheben des nächsten XE-Feldes; Makro wurde aufge-zeichnet und an einer Stelle nachbearbeitet: aus Wrap = wdFindCon-tinue wurde Wrap = wdFindStop; zur Makroausführung muss sich der Cursor vor dem XE-Feld befinden

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „^d XE“
.Replacement.Text = „“
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
‚Options.DefaultHighlightColorIndex = wdYellow
Selection.Range.HighlightColorIndex = wdYellow
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
–––––––––––––––––

Sub xe_feld_hervorheben_alle()


‚ Makro zum Hervorheben aller XE-Felder im Dokument; Makro wurde aufgezeichnet; dann wurden Selection.HomeKey Unit:=wdStory sowie Selection.EndKey Unit:=wdStory und MsgBox „Alle XE-Felder hervor-gehoben“ eingebaut; Wrap = wdFindContinue wurde in Wrap = wdFindStop geändert; außerdem wurde die While…Wend-Schleife einge-baut; zur Makroausführung kann sich der Cursor irgendwo im Dokumenttext befinden

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „^d XE“
.Replacement.Text = „“
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
While Selection.Find.Execute
‚Options.DefaultHighlightColorIndex = wdYellow
Selection.Range.HighlightColorIndex = wdYellow
Selection.MoveRight Unit:=wdCharacter, Count:=1
Wend
Selection.EndKey Unit:=wdStory
MsgBox „Alle XE-Felder hervorgehoben“, vbOKOnly
End Sub
–––––––––––––––––

Sub hervorhebung_loeschen()


‚ Makro zum Aufheben der Hervorhebung_des nächsten XE-Feldes; Makro wurde aufgezeichnet und nicht nachbearbeitet; zur Makroausführung muss sich der Cursor vor dem XE-Feld befinden

Selection.Find.ClearFormatting
Selection.Find.Highlight = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „“
.Replacement.Text = „“
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Options.DefaultHighlightColorIndex = wdNoHighlight
Selection.Range.HighlightColorIndex = wdNoHighlight
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
–––––––––––––––––

Sub hervorhebung_loeschen_alle()


‚ Makro zum Aufheben aller XE-Feld-Hervorhebungen; Makro wurde aufgezeichnet; dann wurden die While…Wend-Schleife und die MsgBox manuell eingebaut; zur Makroausführung kann sich der Cursor irgendwo im Dokumenttext befinden

Selection.Find.ClearFormatting
Selection.Find.Highlight = True
Selection.Find.Replacement.ClearFormatting
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Text = „“
.Replacement.Text = „“
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
While Selection.Find.Execute
Options.DefaultHighlightColorIndex = wdNoHighlight
Selection.Range.HighlightColorIndex = wdNoHighlight
Selection.MoveRight Unit:=wdCharacter, Count:=1
Wend
MsgBox „Alle Hervorhebungen aufgehoben“, vbOKOnly
End Sub
–––––––––––––––––

Sub xe_felder_zaehlen()


‚ Makro zum Zählen der XE-Felder im Dokument; aufgezeichnet wurde die Suche nach dem nächstem XE-Feld; damit die Schleife funktioniert, wurde die Variable n deklariert und eine While-Wend-Schleife eingebaut; auch das Meldungsfenster wurde manuell eingebaut; zur Makroausführung kann sich der Cursor irgendwo im Dokumenttext befinden

Dim n As Integer
n = 0
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „^d XE“
.Replacement.Text = „“
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
While Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
n = n + 1
Wend
Selection.EndKey Unit:=wdStory
MsgBox „Zahl der XE-Felder: “ & n, vbOKOnly
End Sub
–––––––––––––––––

Sub xefeldraus()


‚ Makro zum Löschen eines XE-Feldes; Makro wurde aufgezeichnet und nicht nachbearbeitet; zur Makroausführung muss sich der Cursor vor dem XE-Feld befinden

Selection.Find.ClearFormatting
With Selection.Find
   .Text = „^d XE“
   .Replacement.Text = „“
   .Forward = True
   .Wrap = wdFindStop
   .Format = False
   .MatchCase = True
   .MatchWholeWord = False
   .MatchWildcards = False
   .MatchSoundsLike = False
   .MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.TypeBackspace
End Sub
–––––––––––––––––

Sub xe_feld_loeschen_cursor_drin()


‚Makro zum Löschen des XE-Feldes, in dem sich der Cursor gerade befindet; Makro wurde aufgezeichnet und nicht verändert

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „XE#“
.Replacement.Text = „“
.Forward = False
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
–––––––––––––––––

Sub xefelderraus()


‚ Makro zum Löschen aller XE-Felder in einem Dokument; Makro wurde aufgezeichnet, dann wurden die While…Wend-Schleife und die MsgBox manuell eingebaut; zur Makroausführung muss sich der Cursor am Anfang des Dokuments befinden

Selection.Find.ClearFormatting
With Selection.Find
   .Text = „^d XE“
   .Replacement.Text = „“
   .Forward = True
   .Wrap = wdFindStop
   .Format = False
   .MatchCase = True
   .MatchWholeWord = False
   .MatchWildcards = False
   .MatchSoundsLike = False
   .MatchAllWordForms = False
End With
While Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.TypeBackspace
Wend
MsgBox „Alle XE-Felder entfernt“, vbOKOnly
End Sub
–––––––––––––––––

Sub index_gesamt()


‚ Makro zum Einfügen des Gesamtindexes; Makro wurde aufgezeichnet und nicht nachbearbeitet; zur Makroausführung sollte sich der Cur-sor dort befinden, wo der Index eingebaut werden soll (am Ende des Dokuments oder in einem separaten Dokument)

With ActiveDocument
.Indexes.Add Range:=Selection.Range, HeadingSeparator:= _
wdHeadingSeparatorNone, Type:=wdIndexIndent,
RightAlignPageNumbers:= _
False, NumberOfColumns:=2, IndexLanguage:=wdGerman
.Indexes(1).TabLeader = wdTabLeaderDots
End With
End Sub
–––––––––––––––––