宏以使用excel行创建一个单词并找到一个特定的单词并突出显示该单词

时间:2019-05-23 10:48:04

标签: excel vba

我想找到文本“ excel”,并在整个word文档中用黄色突出显示。

我尝试了以下操作:

With ActiveDocument.Content.Find 
 .ClearFormatting 
 .Font.Bold = True 
 With .Replacement 
 .ClearFormatting 
 .Font.Bold = False 
 End With 
 .Execute FindText:="", ReplaceWith:="", _ 
 Format:=True, Replace:=wdReplaceAll 
End With

但这不起作用。

这是我用来从excel工作表生成单词的代码,但是这样做时,我想找到一个单词并将其突出显示。

Sub WordTemp()
    Dim TextEnter As String
    Dim RowNum As Integer
    Dim wordApp As Object
    Dim LastRow, LastCol, CurrentRow, CurrentCol As Long

    Set wordApp = CreateObject("word.application")
    wordApp.Visible = True

    wordApp.Documents.Add _
    Template:="", _
    NewTemplate:=False

    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    LastCol = Cells(1, Columns.Count).End(xlToLeft).Column

    For CurrentRow = 2 To LastRow
        TextEnter = ""

        For CurrentCol = 1 To LastCol
            TextEnter = TextEnter & Cells(1, CurrentCol).Value & "   " & Cells(CurrentRow, CurrentCol).Value & vbCrLf
        Next CurrentCol

        wordApp.Selection.TypeParagraph
        wordApp.Selection.TypeText Text:=TextEnter
        wordApp.Selection.TypeText Text:="Thumbnail:" & vbNewLine & "<<Insert thumbnail here>>" & vbNewLine & "SAT: " & vbNewLine & vbNewLine & "LAT: " & vbNewLine & vbNewLine & "Revised Category: " & vbNewLine
        wordApp.Selection.InsertBreak Type:=7
    Next CurrentRow


End Sub

发现“ excel”一词(所有情况),并以黄色突出显示。

0 个答案:

没有答案