Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

VBA Suchen&Ersetzen fett/kursiv/highlight/unterstr

Forumthread: VBA Suchen&Ersetzen fett/kursiv/highlight/unterstr

VBA Suchen&Ersetzen fett/kursiv/highlight/unterstr
09.04.2018 19:04:43
Anja
Ihr lieben Retter in der Not,
ich habe ein Makro geschrieben, das mir in langen Dokumenten alle
  • gehighlighteten

  • unterstrichenen

  • fetten und/oder

  • kursiven

  • Wörter "markiert" (mit Textzeichen/Symbolabfolgen verseht), damit ich beim Kopieren und Einfügen von "nur Text" in ein neues Dokument per Knopfdruck wieder alles gehighlighted, fett, kursiv und unterstrichen habe, was vorher auch so formatiert war (Ziel ist es dabei, dass alle fremden Styles auch weg sind, deshalb das Einfügen von nur Text in ein neues sauberes Doc.).
    Leider funktioniert das Makro nicht zu 100%.
    1. Kommt nun auf einmal imer der Dialog, dass nichts gefunden wurde und ob die Suche von vorne beginnen soll (beim anklicken von ok, findet er dann aber was).
    2. Wenn ein Wort Fett kursiv und gehighlightet ist wird beim umwandeln im neuen Dokument immer der gesamte darauf folgende ganzer Absatz fett markiert und nicht nur das Wort am Anfang, Gehioghlighted wird dann gar nix.
    Kann mir jemamnd helfen, den oder die Fehler zu finden? Sitze daran nun schon seit Wochen und habe es immer wieder verbessert aber irgendwie bleibt es fehlerhaft :((
    Hier die zwei Makros:
    
    Sub aabFettKursivQuelldok()
    ' aaFettKursivQuelldok Macro
    ' marks all highlighted words
    Selection.Find.ClearFormatting
    Selection.Find.Font.Underline = wdUnderlineSingle
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "(?@>)"
    .Replacement.Text = "°°°°^&''''"
    .Forward = True
    .Wrap = wdFindAsk
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ' marks all underlined words
    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
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ' marks all bold words
    Selection.Find.ClearFormatting
    Selection.Find.Font.Bold = True
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "(?@>)"
    .Replacement.Text = "####^&&&&&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ' marks all italic words
    Selection.Find.ClearFormatting
    Selection.Find.Font.Italic = True
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "(?@>)"
    .Replacement.Text = "~~^&+++"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    

    Sub aabFettKursivZieldok()
    '
    ' aaFettKursivZieldok Macro
    '
    ' replaces all underlined-marked words
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Underline = wdUnderlineSingle
    With Selection.Find
    .Text = "°°°°(?@>)''''"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ' replaces all highlighted-marked words
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Highlight = True
    With Selection.Find
    .Text = "§§§(?@>)%%%%"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ' replaces all bold-marked words
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Bold = True
    With Selection.Find
    .Text = "####(?@>)&&&&"
    .Replacement.Text = "^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ' replaces all italic-marked words
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Font.Italic = True
    With Selection.Find
    .Text = "~~(?@>)+++"
    .Replacement.Text = "^&"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ' deletes all marks:
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "°°°°"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "''''"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "§§§"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "%%%%"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "####"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "&&&&"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
    .Text = "~~"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
    .Text = "+++"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

    Anzeige

    1
    Beitrag zum Forumthread
    Beitrag zu diesem Forumthread

    Betreff
    Datum
    Anwender
    Anzeige
    AW: VBA Suchen&Ersetzen fett/kursiv/highlight/unterstr
    09.04.2018 19:09:31
    Anja
    P.S. Gibt es zudem eine Möglichkeit die Silbentrennung per VBA im ganzen Dokument auszuschalten?
    Anzeige
    ;

    Forumthreads zu verwandten Themen

    Anzeige
    Anzeige
    Entdecke relevante Threads

    Schau dir verwandte Threads basierend auf dem aktuellen Thema an

    Alle relevanten Threads mit Inhaltsvorschau entdecken

    Beliebteste Forumthreads (12 Monate)

    Anzeige
    Anzeige
    Entdecke mehr
    Finde genau, was du suchst

    Die erweiterte Suchfunktion hilft dir, gezielt die besten Antworten zu finden

    Suche nach den besten Antworten
    Unsere beliebtesten Threads

    Entdecke unsere meistgeklickten Beiträge in der Google Suche

    Top 100 Threads jetzt ansehen
    Anzeige