Indexing mit Word: Makrocodes, Teil 3

Contents

Makros zum Thema „Seitenbereichsangaben“

Weitere Makros sind in Teil 1 und Teil 2 zu finden.

Sub pagefeld_zwischenablage()


‚fügt hilfsweise das Page-Feld am Anfang des Dokuments ein und schneidet es dann aus, womit es sich in der Zwischenablage befindet; wird für die nachfolgenden Schritte benötigt


Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
„PAGE „, PreserveFormatting:=False
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Cut
End Sub

Sub page_in_standardschr()


‚fügt das Page-Feld in Standardschrift in den XE-Feldern ein


Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles( _
„Absatz-Standardschriftart“)
With Selection.Find
.Text = „^d Page“
.Replacement.Text = „^&“
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Sub phase_zwei_a_eins_page_in_xe_all()


‚ dient in Phase 2 a dazu, das Page-Feld hilfsweise zu erzeugen, auszuschneiden und dann am Ende jedes XE-Feldes einzufügen, und zwar mit dem Zeichenformat „Absatz-Standardschriftart“


Selection.HomeKey Unit:=wdStory
Application.Run MacroName:=“nichtdr_ein“
‚Feldsyntax muss nicht sichtbar sein, weil nicht nach dem Page-Feld gesucht wird
Application.Run MacroName:=“pagefeld_zwischenablage“
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „(XE „“*)“““
.Replacement.Text = „\1:^c“““
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run MacroName:=“page_in_standardschr“
MsgBox „Page-Feld am Ende aller XE-Felder eingebaut“, vbOKOnly
End Sub

Sub phase_zwei_a_zwei_reihenfolge_page_all()


‚ dient in Phase 2 a dazu, die Reihenfolge von Code und Page-Feld umzudrehen, entfernt einen Doppelpunkt


Application.Run MacroName:=“nichtdr_ein“
Application.Run MacroName:=“feldsyntax_ein“
’nicht druckbare Zeichen und Feldsyntax müssen sichtbar sein,
‚weil nach dem Page-Feld im XE-Feld gesucht wird
Selection.HomeKey Unit:=wdStory
Application.Run MacroName:=“pagefeld_zwischenablage“
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „:<:^d Page“
.Replacement.Text = „:^c<„
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „:>:^d Page“
.Replacement.Text = „:^c>“
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run MacroName:=“page_in_standardschr“
MsgBox „Reihenfolge von Seitenbereich-Code und Page-Feld umgedreht“, vbOKOnly
End Sub

Sub einfuegen_in_absatzstandardformat()


‚ fügt kopierten Text im Absatzstandardformat an Cursoposition ein


Selection.PasteAndFormat (wdFormatSurroundingFormattingWithEmphasis)
End Sub

Sub nichtdr_aus()


‚ schaltet die Anzeige der nichtdruckbaren Zeichen aus


Dim a As Long
ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
ShowAll
‚MsgBox „Sind die Absatzmarken zu sehen?“, vbYesNo
a = MsgBox(„Sind die Absatzmarken zu sehen?“, vbYesNo)
‚MsgBox (a)
‚wenn die Antwort „nein“ lautet, ergibt sich der Wert 7; bei „ja“ ergibt sich 6
If a = „6“ Then
ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
ShowAll
End If
End Sub

Sub nichtdr_ein()


‚ schaltet die Anzeige der nichtdruckbaren Zeichen ein


Dim a As Long
ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
ShowAll
a = MsgBox(„Sind die Absatzmarken zu sehen?“, vbYesNo)
‚MsgBox (a)
‚wenn die Antwort „nein“ lautet, ergibt sich der Wert 7; bei „ja“ ergibt sich 6
If a = „7“ Then
ActiveWindow.ActivePane.View.ShowAll = Not ActiveWindow.ActivePane.View. _
ShowAll
End If
End Sub


Sub phase_zwei_a_drei_aktual()


‚ dient in Phase 2 a zur Aktualisierung der Page-Felder


Application.Run MacroName:=“feldsyntax_aus“
Application.Run MacroName:=“nichtdr_aus“
’nichtdruckbare Zeichen und Feldsyntax dürfen nicht sichtbar sein,
‚damit das Page-Feld die korrekten Seitenzahlen erzeugt;
‚Aktualisierung wirkt auch auf nichtsichtbare Felder!
Selection.WholeStory
Selection.Fields.Update
MsgBox „Alle Felder aktualisiert.“, vbOKOnly
End Sub

Sub feldsyntax_aus()


‚ schaltet die Anzeige der Feldsyntax_aus‘

Dim a As Long
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
‚MsgBox „Sind die Absatzmarken zu sehen?“, vbYesNo
a = MsgBox(„Ist die Feldsyntax zu sehen?“, vbYesNo)
‚MsgBox (a)
‚wenn die Antwort „nein“ lautet, ergibt sich der Wert 7; bei „ja“ ergibt sich 6
If a = „6“ Then
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
End If

End Sub

Sub feldsyntax_ein()


‚ schaltet die Anzeige der Feldsyntax ein


Dim a As Long
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
‚MsgBox „Sind die Absatzmarken zu sehen?“, vbYesNo
a = MsgBox(„Ist die Feldsyntax zu sehen?“, vbYesNo)
‚MsgBox (a)
‚wenn die Antwort „nein“ lautet, ergibt sich der Wert 7; bei „ja“ ergibt sich 6
If a = „7“ Then
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
End If

End Sub

Sub phase_zwei_a_vier_fix()


‚ dient in Phase 2 a dazu, die Inhalte der Page-Felder zu fixieren


Application.Run MacroName:=“nichtdr_ein“
‚es reicht, wenn die nichtdruckbaren Zeichen angezeigt werden, denn dann sind auch
‚die Ergebnisse der Page-Felder in den XE-Feldern zu sehen und können fixiert werden
Selection.WholeStory
Selection.Fields.Unlink
MsgBox „Alle Felder fixiert.“, vbOKOnly
End Sub

Sub phase_zwei_a_fünf_fuehr_null()


‚dient in Phase 2 a dazu, führende Nullen bei Seitenverweisen einzubauen


Application.Run MacroName:=“nichtdr_ein“
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „:([0-9][0-9]““)“
.Replacement.Text = „:0\1“
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = „:([0-9][0-9]\<„“)“
.Replacement.Text = „:0\1“
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = „:([0-9][0-9]\>““)“
.Replacement.Text = „:0\1“
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = „:([0-9]““)“
.Replacement.Text = „:00\1“
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = „:([0-9]\<„“)“
.Replacement.Text = „:00\1“
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = „:([0-9]\>““)“
.Replacement.Text = „:00\1“
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
MsgBox „Führende Nullen eingebaut.“, vbOKOnly
End Sub

Sub phase_zwei_b_eins_index_fix()


‚ dient in Phase 2 b dazu, den Index_zu fixieren


Application.Run MacroName:=“nichtdr_aus“
Selection.EndKey Unit:=wdStory
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.Fields.Update
Selection.Fields.Unlink
MsgBox „Index fixiert.“, vbOKOnly
End Sub

Sub phase_zwei_b_zwei_word_int_seitz()


‚ dient in Phase 2 b dazu, die Word-internen Seitenverweise zu löschen


Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = “ <[0-9]{1;3}>“
.Replacement.Text = „“
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
MsgBox „Word-eigene Seitenverweise gelöscht.“, vbOKOnly
End Sub

Sub phase_zwei_b_drei_von_bis_in_zeile()


‚ dient in Phase 2 b dazu, Von-Bis-Angaben in eine Zeile zu bringen 


Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = “ <[0-9]{1;3}>“
.Replacement.Text = „“
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „([0-9]{3;3})\<^013([0-9]{3;3})\>“
.Replacement.Text = „\1–\2“
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
MsgBox „Von-Bis-Angaben in eine Zeile gebracht.“, vbOKOnly
End Sub

Sub phase_zwei_b_vier_form_norm()


‚ dient in Phase 2 b dazu, die Formatvorlagen zu normieren; dabei werden die Hilfscodes # und ## eingeführt  


Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles(„Index 2“)
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles(„Index 1“)
With Selection.Find
.Text = „(<[0-9]{3;3}>–<[0-9]{3;3}>)“
.Replacement.Text = „#\1“
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = „(<[0-9]{3;3}>)“
.Replacement.Text = „#\1“
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles(„Index 3“)
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles(„Index 2“)
With Selection.Find
.Text = „(<[0-9]{3;3}>–<[0-9]{3;3}>)“
.Replacement.Text = „##\1“
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = „(<[0-9]{3;3}>)“
.Replacement.Text = „##\1“
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
MsgBox „Formatvorlagen normiert.“, vbOKOnly
End Sub

Sub phase_zwei_b_fuenf_seitz_hochziehen()


‚dient in Phase 2 b dazu, alle Seitenverweise in Eintragstextzeile hochzuziehen 


Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „^013#([0-9]{3;3})“
.Replacement.Text = „, \1“
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = „^013##([0-9]{3;3})“
.Replacement.Text = „, \1“
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
MsgBox „Seitenverweise zusammengeführt und hochgezogen.“, vbOKOnly
End Sub

Sub phase_zwei_b_sechs_komma_weg()


‚dient in Phase 2 b dazu, das Komma nach dem Eintragstext durch ein Leerzeichen zu ersetzen (sodass nach dem Eintragstext zwei Leerzeichen als Trenner zu den Seitenzahlen stehen)


Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „([A-zÄÖÜäöüß\)]), ([0-9]{3;3})“
.Replacement.Text = „\1 \2“
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
MsgBox „Komma vor erstem Seitenverweis durch doppeltes Leerzeichen ersetzt.“, vbOKOnly
End Sub

Sub phase_zwei_b_sieben_nullen_weg()


‚ dient in Phase 2 b dazu, die führenden Nullen zu entfernen‘

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = „<00([1-9])>“
.Replacement.Text = „\1“
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = „<0([1-9][0-9])>“
.Replacement.Text = „\1“
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
MsgBox „Führende Nullen entfernt.“, vbOKOnly
End Sub