Thema Datum  Von Nutzer Rating
Antwort
Rot Firmennamen ersetzen in Kopf/Fußzeile un Haupttext
26.10.2015 15:16:31 Fabwal
NotSolved

Ansicht des Beitrags:
Von:
Fabwal
Datum:
26.10.2015 15:16:31
Views:
1717
Rating: Antwort:
  Ja
Thema:
Firmennamen ersetzen in Kopf/Fußzeile un Haupttext

Hallo liebe Gemeinde,

 

ich habe ein Problem mit dem Programmcode. Office (in diesem fall Word) stürzt immer ab bei der ausführung des Programms. Ich nehme an es liegt an der Codelänge oder ähnliches, da wenn ich einen Breakpoint setze und manuell jede weitere Routine starte (Also Pause>ausführen>Pause>ausführenetc.) funktioniert er. ich habe es auch schon mit system.pause versucht leider ohne erfolg.

Hat jemand eine Idee zu unten angebeben Code. kürzer und Ram sparender hinbekomme.

Also Code funktioniert nur wenn man manuell einen breakpoint setzt.

Sub FirmenNamenTauschen(Verz As String, DName As String)
Dim Kundenname As String
On Error Resume Next
Documents.Open (Verz & DName)

Kundenname = Userform1.Kundenkuerzel
If UserForm3.TextBox1 > "" Then Kundenname = UserForm3.TextBox1

Dim oStory As Range

'1:::::
    For Each oStory In ActiveDocument.StoryRanges
        oStory.Find.ClearFormatting
        oStory.Find.Replacement.ClearFormatting
        With oStory.Find
            .Text = "abc GmbH"
            .Replacement.Text = Kundenname
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        oStory.Find.Execute Replace:=wdReplaceAll
        'Jetzt haben wir den Hauptbereich abgearbeitet - nun noch der Rest
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Find.ClearFormatting
            oStory.Find.Replacement.ClearFormatting
            With oStory.Find
                .Text = abc"
                .Replacement.Text = Kundenname
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            oStory.Find.Execute Replace:=wdReplaceAll
        Wend
    Next
'2:::::
For Each oStory In ActiveDocument.StoryRanges
        oStory.Find.ClearFormatting
        oStory.Find.Replacement.ClearFormatting
        With oStory.Find
            .Text = "abc GmbH"
            .Replacement.Text = Kundenname
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        oStory.Find.Execute Replace:=wdReplaceAll
        'Jetzt haben wir den Hauptbereich abgearbeitet - nun noch der Rest
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Find.ClearFormatting
            oStory.Find.Replacement.ClearFormatting
            With oStory.Find
                .Text = "abc GmbH"
                .Replacement.Text = Kundenname
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            oStory.Find.Execute Replace:=wdReplaceAll
        Wend
    Next

'2:::::
For Each oStory In ActiveDocument.StoryRanges
        oStory.Find.ClearFormatting
        oStory.Find.Replacement.ClearFormatting
        With oStory.Find
            .Text = "abc.de"
            .Replacement.Text = Kundenname
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        oStory.Find.Execute Replace:=wdReplaceAll
        'Jetzt haben wir den Hauptbereich abgearbeitet - nun noch der Rest
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Find.ClearFormatting
            oStory.Find.Replacement.ClearFormatting
            With oStory.Find
                .Text = "abc.de"
                .Replacement.Text = Kundenname
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            oStory.Find.Execute Replace:=wdReplaceAll
        Wend
    Next
'3:::::
For Each oStory In ActiveDocument.StoryRanges
        oStory.Find.ClearFormatting
        oStory.Find.Replacement.ClearFormatting
        With oStory.Find
            .Text = "abC.de"
            .Replacement.Text = Kundenname
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        oStory.Find.Execute Replace:=wdReplaceAll
        'Jetzt haben wir den Hauptbereich abgearbeitet - nun noch der Rest
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Find.ClearFormatting
            oStory.Find.Replacement.ClearFormatting
            With oStory.Find
                .Text = "abC.de"
                .Replacement.Text = Kundenname
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            oStory.Find.Execute Replace:=wdReplaceAll
        Wend
    Next

'2:::::
For Each oStory In ActiveDocument.StoryRanges
        oStory.Find.ClearFormatting
        oStory.Find.Replacement.ClearFormatting
        With oStory.Find
            .Text = "Boxx"
            .Replacement.Text = Kundenname
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        oStory.Find.Execute Replace:=wdReplaceAll
        'Jetzt haben wir den Hauptbereich abgearbeitet - nun noch der Rest
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Find.ClearFormatting
            oStory.Find.Replacement.ClearFormatting
            With oStory.Find
                .Text = "Boxx"
                .Replacement.Text = Kundenname
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            oStory.Find.Execute Replace:=wdReplaceAll
        Wend
    Next

'2:::::
For Each oStory In ActiveDocument.StoryRanges
        oStory.Find.ClearFormatting
        oStory.Find.Replacement.ClearFormatting
        With oStory.Find
            .Text = "BOXX"
            .Replacement.Text = Kundenname
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        oStory.Find.Execute Replace:=wdReplaceAll
        'Jetzt haben wir den Hauptbereich abgearbeitet - nun noch der Rest
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Find.ClearFormatting
            oStory.Find.Replacement.ClearFormatting
            With oStory.Find
                .Text = "BOXX"
                .Replacement.Text = Kundenname
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            oStory.Find.Execute Replace:=wdReplaceAll
        Wend
    Next


'2:::::
For Each oStory In ActiveDocument.StoryRanges
        oStory.Find.ClearFormatting
        oStory.Find.Replacement.ClearFormatting
        With oStory.Find
            .Text = "boxx"
            .Replacement.Text = Kundenname
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        oStory.Find.Execute Replace:=wdReplaceAll
        'Jetzt haben wir den Hauptbereich abgearbeitet - nun noch der Rest
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Find.ClearFormatting
            oStory.Find.Replacement.ClearFormatting
            With oStory.Find
                .Text = "boxx"
                .Replacement.Text = Kundenname
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            oStory.Find.Execute Replace:=wdReplaceAll
        Wend
    Next

'2:::::
For Each oStory In ActiveDocument.StoryRanges
        oStory.Find.ClearFormatting
        oStory.Find.Replacement.ClearFormatting
        With oStory.Find
            .Text = "BoxX"
            .Replacement.Text = Kundenname
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        oStory.Find.Execute Replace:=wdReplaceAll
        'Jetzt haben wir den Hauptbereich abgearbeitet - nun noch der Rest
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Find.ClearFormatting
            oStory.Find.Replacement.ClearFormatting
            With oStory.Find
                .Text = "BoxX"
                .Replacement.Text = Kundenname
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            oStory.Find.Execute Replace:=wdReplaceAll
        Wend
    Next

'2:::::
For Each oStory In ActiveDocument.StoryRanges
        oStory.Find.ClearFormatting
        oStory.Find.Replacement.ClearFormatting
        With oStory.Find
            .Text = "boxx.de"
            .Replacement.Text = Kundenname
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        oStory.Find.Execute Replace:=wdReplaceAll
        'Jetzt haben wir den Hauptbereich abgearbeitet - nun noch der Rest
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Find.ClearFormatting
            oStory.Find.Replacement.ClearFormatting
            With oStory.Find
                .Text = "boxx"
                .Replacement.Text = Kundenname
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            oStory.Find.Execute Replace:=wdReplaceAll
        Wend
    Next
    
    '2:::::
For Each oStory In ActiveDocument.StoryRanges
        oStory.Find.ClearFormatting
        oStory.Find.Replacement.ClearFormatting
        With oStory.Find
            .Text = "press.de"
            .Replacement.Text = Kundenname
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        oStory.Find.Execute Replace:=wdReplaceAll
        'Jetzt haben wir den Hauptbereich abgearbeitet - nun noch der Rest
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Find.ClearFormatting
            oStory.Find.Replacement.ClearFormatting
            With oStory.Find
                .Text = "press.de"
                .Replacement.Text = Kundenname
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            oStory.Find.Execute Replace:=wdReplaceAll
        Wend
    Next
    
'2:::::
For Each oStory In ActiveDocument.StoryRanges
        oStory.Find.ClearFormatting
        oStory.Find.Replacement.ClearFormatting
        With oStory.Find
            .Text = "xxx"
            .Replacement.Text = "Disposition"
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        oStory.Find.Execute Replace:=wdReplaceAll
        'Jetzt haben wir den Hauptbereich abgearbeitet - nun noch der Rest
        While Not (oStory.NextStoryRange Is Nothing)
            Set oStory = oStory.NextStoryRange
            oStory.Find.ClearFormatting
            oStory.Find.Replacement.ClearFormatting
            With oStory.Find
               .Text = "Zuglaufsteuerung"
            .Replacement.Text = "Disposition"
                .Forward = True
                .Wrap = wdFindContinue
                .Format = False
                .MatchCase = True
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            oStory.Find.Execute Replace:=wdReplaceAll
        Wend
    Next

If Userform1.TextBox1 > "" Then
Call Speichern
ActiveDocument.Close
End If
If UserForm3.TextBox1 > "" Then
Call Speichern
ActiveDocument.Close
End If
End Sub

 


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
Rot Firmennamen ersetzen in Kopf/Fußzeile un Haupttext
26.10.2015 15:16:31 Fabwal
NotSolved