![]() |
Tipp 0288
|
Wörter suchen und zählen
|
![](/vb/images/down.gif) |
|
Autor/Einsender: Datum: |
|
Angie 19.11.2002 |
|
Entwicklungsumgebung: |
|
Word 97 |
|
|
Mit folgender Prozedur lässt sich nicht nur ermitteln, wie oft ein bestimmtes Wort oder
auch Wortfolge im Hauptteil eines Dokuments vorkommt, sondern auch wie oft das Wort/die
Wortfolge auf der jeweiligen Seite vorhanden ist.
|
|
|
Option Explicit
Private Const mc_MsgTitle As String = "VB-fun-Demo"
Sub WortSuchenUndSeitenzahlAusgeben()
Dim objWDDoc As Word.Document
Dim intPagesCnt As Integer
Dim strFind As String
Dim intCntSum As Integer
Dim intCnt As Integer
Dim intPageNum As Integer
Dim aintFound() As Integer
Dim i As Integer
Dim strMsg As String
strFind = InputBox("Bitte geben Sie den Suchbegriff ein:", _
Title:=mc_MsgTitle, Default:="Hallihallo...")
If StrPtr(strFind) <> 0 Then
If Len(strFind) > 0 Then
Application.ScreenUpdating = False
Set objWDDoc = ActiveDocument
objWDDoc.Range(0, 0).Select
objWDDoc.Repaginate
intPagesCnt = objWDDoc.ComputeStatistics(wdStatisticPages)
ReDim aintFound(1 To intPagesCnt)
intCntSum = 0
intCnt = 0
intPageNum = 0
With Selection.Find
.ClearFormatting
.Forward = True
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.Text = strFind
.Execute
While .Found = True
intCntSum = intCntSum + 1
If intPageNum = Selection.Information( _
wdActiveEndPageNumber) Then
intCnt = intCnt + 1
Else
intCnt = 1
intPageNum = Selection.Information( _
wdActiveEndPageNumber)
End If
aintFound(intPageNum) = intCnt
.Execute
Wend
End With
If intCntSum > 0 Then
strMsg = "Der Suchbegriff '" & strFind & _
"' kommt insgesamt " & CStr(intCntSum) & _
" mal im Hauptteil des Dokumentes vor!" & _
vbCrLf & vbCrLf
For i = 1 To UBound(aintFound)
If aintFound(i) > 0 Then
strMsg = strMsg & CStr(aintFound(i)) & _
" mal auf Seite " & i & vbCrLf
End If
Next i
strMsg = Mid(strMsg, 1, Len(strMsg) - 2)
MsgBox strMsg, vbOKOnly + vbInformation, mc_MsgTitle
Else
MsgBox "Das Wort '" & strFind & "' kommt " & _
"im Hauptteil des Dokumentes nicht vor!", _
vbOKOnly + vbInformation, mc_MsgTitle
End If
objWDDoc.Range(0, 0).Select
Application.ScreenUpdating = True
Set objWDDoc = Nothing
End If
End If
End Sub
|
|
|
|
Die im Download befindliche *.bas-Datei kann in Word im VB-Editor importiert werden.
|
|
Windows-Version |
95 |
![](/vb/images/haken.gif) |
|
98/SE |
![](/vb/images/haken.gif) |
|
ME |
![](/vb/images/haken.gif) |
|
NT |
![](/vb/images/haken.gif) |
|
2000 |
![](/vb/images/haken.gif) |
|
XP |
![](/vb/images/haken.gif) |
|
Vista |
![](/vb/images/haken.gif) |
|
Win
7 |
![](/vb/images/haken.gif) |
|
|
Word-Version |
95 |
![](/vb/images/frage.gif) |
|
97 |
![](/vb/images/haken.gif) |
|
2000 |
![](/vb/images/haken.gif) |
|
2002
(XP) |
![](/vb/images/haken.gif) |
|
2003 |
![](/vb/images/haken.gif) |
|
2007 |
![](/vb/images/haken.gif) |
|
2010 |
![](/vb/images/haken.gif) |
|
|
|
Download (2,3 kB)
|
Downloads bisher: [ 1007 ]
|
|
|