VBA:格式化文档中的所有字体 [英] VBA: Format all font in document
本文介绍了VBA:格式化文档中的所有字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在MS Word中使用此代码时,此代码正在尝试从excel运行。我想使用相同的字体类型和相同的字体大小来格式化文档中的所有文本。
'通用格式化文档字体类型和大小
Selection.WholeStory
Selection.Font.Name =Calibri
Selection.Font.Size = 11
结束
这一个也没有工作:
ActiveDocument.Range.Font.Color = wdColorAutomatic
/ pre>
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
'~~>这包含您的搜索词
strToFind =交易,合同,签署,奖励
'~~>创建一个文本数组
MyAr = Split(strToFind,,)
FileToOpen = Application.GetOpenFilename _
(Title:=请选择一个文件导入,_
FileFilter:=Word Files * .docx(* .docx))
如果FileToOpen = False然后退出Sub
设置objWord = CreateObject(Word.Application)
'~~>打开相关的单词文档
Set objDoc = objWord.Documents.Open(FileToOpen)
objWord.Visible = True
设置Rng = objDoc.Content
与Rng
.Font.Name =Calibri
.Font.Size = 11
结束
结束Sub
This code worked when used in MS Word, now trying to run from excel. I want to format all the text in the document with the same font type and the same font size.
'Format document with universal font type and size Selection.WholeStory Selection.Font.Name = "Calibri" Selection.Font.Size = 11 End With
This one also did not work:
ActiveDocument.Range.Font.Color = wdColorAutomatic ActiveDocument.Range.Font.Name = "Calibri" ActiveDocument.Range.Font.Size = 11
解决方案I guess this is in continuation to your last question. Try this. I have not deleted certain declarations from the previous code.
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
这篇关于VBA:格式化文档中的所有字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文