3

此代码在 MS Word 中使用时有效,现在尝试从 excel 运行。我想用相同的字体类型和相同的字体大小来格式化文档中的所有文本。

'Format document with universal font type and size
    Selection.WholeStory
    Selection.Font.Name = "Calibri"
    Selection.Font.Size = 11
    End With

这个也不起作用:

ActiveDocument.Range.Font.Color = wdColorAutomatic
ActiveDocument.Range.Font.Name = "Calibri"
ActiveDocument.Range.Font.Size = 11
4

2 回答 2

4

我想这是你最后一个问题的延续。尝试这个。我没有从之前的代码中删除某些声明。

Const wdFindContinue = 1

Sub FnFindAndFormat()
    Dim FileToOpen
    Dim objWord As Object, objDoc As Object, Rng As Object
    Dim MyAr() As String, strToFind As String
    Dim i As Long

    '~~> This holds your search words
    strToFind = "deal,contract,sign,award"

    '~~> Create an array of text to be found
    MyAr = Split(strToFind, ",")

    FileToOpen = Application.GetOpenFilename _
    (Title:="Please choose a file to import", _
    FileFilter:="Word Files *.docx (*.docx),")

    If FileToOpen = False Then Exit Sub

    Set objWord = CreateObject("Word.Application")
    '~~> Open the relevant word document
    Set objDoc = objWord.Documents.Open(FileToOpen)

    objWord.Visible = True

    Set Rng = objDoc.Content

    With Rng
        .Font.Name = "Calibri"
        .Font.Size = 11
    End With
End Sub
于 2013-11-13T21:59:37.273 回答
0

在顶部设置常量:

常量 wdColorAutomatic = -16777216

objDoc.Range.Font.Color = wdColorAutomatic
        objDoc.Range.Font.Name = "Calibri"
        objDoc.Range.Font.Size = 11
于 2013-11-13T22:02:54.370 回答