Bir belgede aranan birden fazla kelimeyi nasıl vurgularım?


1

Aranacak kelimeleri olan bir dosyam var. Bu kelimeleri aktif belgede vurgulamak istiyorum.

Örneğin: style.docx:

school
Agro commercial
abovementioned
some words
physics

Aktif belge:

Yukarıda belirtilen ve okul gibi bazı kelimeleri açıklamak için satırlar budur.
Bu çizginin sonu.

Beklenen çıktı: yukarıda belirtilen bazı kelimeler, okul aktif belgede vurgulanmalıdır.

Aşağıdaki kodu denedim:

   Dim docTitle As Document
    Dim docStyle As Document
    Set docTitle = Documents.Open(FileName:="C:\Documents and Settings\quads\Desktop\stylesheet.docx", ConfirmConversions:=True)
    Set docStyle = Documents.Open(FileName:="C:\Documents and Settings\quads\Desktop\files\Albala D-ed.doc", ConfirmConversions:=True)

    Dim char As Long
    Dim x As Long
    Dim count As Integer


    Dim Para As Paragraph

    For Each Para In docTitle.Paragraphs
      If Len(Para.Range.Text) > 0 Then
                ActiveDocument.Range(0, 0).Select

        Selection.Find.ClearFormatting
                With Selection.Find
                .Text = Left(Para.Range.Text, Len(Para.Range.Text) - 1)
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindContinue
                .Format = True
                .MatchCase = False
                .MatchWholeWord = False
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
            Selection.Find.Execute

        End If
        ActiveDocument.Range(0, 0).Select

    Next Para

Kodumu çalıştırmak için tring devam ediyorum ama hayır şans. Ayrıca dosya ismini söylemeden belirli bir klasörde ("dosyalar") arama yapmak istiyorum. Sadece o klasördeki tüm dosyaları aramam gerekiyor. Lütfen yardım edin!

Yanıtlar:


0

Birden fazla aranan kelimeyi (diğer dosyadan) vurgulayan sarı renkte cevabımı yapıştırdım. Arama kelime dosyası ve vurgulanacak dosya, dosya iletişim nesnesi kullanılarak seçilebilir.

Dim filepath As String
Dim filename As FileDialog
Dim stylepath As String
Dim stylename As FileDialog
MsgBox ("Please choose Style File Name")

Set stylename = Application.FileDialog(filedialogtype:=msoFileDialogFilePicker)
If stylename.Show Then
stylepath = stylename.SelectedItems(1)
End If

Set filename = Application.FileDialog(filedialogtype:=msoFileDialogFilePicker)
If filename.Show Then
filepath = filename.SelectedItems(1)
End If

Dim range As range
Dim i As Long
Dim arr() As String
Dim docTitle As Document
Dim docStyle As Document
    Set docTitle = Documents.Open(stylepath)
    Set docStyle = Documents.Open(filepath)


arr = Split(docTitle.Content.Text, Chr(13))

For i = 0 To UBound(arr)
Set range = docStyle.range

With range.Find
.Text = arr(i)
.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

Do While .Execute(Forward:=True) = True
range.HighlightColorIndex = wdYellow

Loop

End With
Next
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.