Word 2002 SP3 Makroerstellung



  • Ich suhe ein Makro mit dem man zählen kann, wie oft ein Wort in einem Worddokument vorkommt. Wer kann helfen?



  • Sub AnzahlWorte()
    Dim rngRange As Word.Range
    Dim lngAnzahlWorte As Long
    Dim strText As String
    Dim lngL As Long
    Dim strDasWort4 As String
    Dim lngWortNr As Long
    
    Set rngRange = ActiveDocument.Range
    lngAnzahlWorte = rngRange.ComputeStatistics(wdStatisticWords)
    
    Do While Len(strText) <> lngL
     lngL = Len(strText)
     strText = Replace(strText, "  ", " ", 1, -1, 1)
    Loop
    lngAnzahlWorte = UBound(Split(strText, " ", -1, 1))
    MsgBox lngAnzahlWorte, , "Anzahl Worte im Doument"
    
    'wie oft kommt das 4. Wort im Documet im Gesamten Text vor:
    lngWortNr = 1
    strDasWort4 = Split(strText, " ", -1, 1)(lngWortNr - 1)
    lngAnzahlWorte = (Len(strText) - Len(Replace(strText, strDasWort4, "", 1, -1, 1))) / Len(strDasWort4)
    MsgBox lngAnzahlWorte, , "So oft gibts das Wort: " & strDasWort4
    
    End Sub
    

    Nach 30s Google ...

    Gruss IchBinNichtSicher


Anmelden zum Antworten