VBA:格式化文档中的所有字体
这个代码在MS Word中使用,现在试图从Excel中运行。 我想要使用相同的字体types和相同的字体大小来格式化文档中的所有文本。
'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
我想这是对你最后一个问题的继续。 尝试这个。 我没有从前面的代码中删除某些声明。
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
在顶部设置常量:
Const wdColorAutomatic = -16777216
objDoc.Range.Font.Color = wdColorAutomatic objDoc.Range.Font.Name = "Calibri" objDoc.Range.Font.Size = 11