[英]Change font on selected text in macro for MS Word
I am having to add some functionality to an existing macro for MS Word.我必须为 MS Word 的现有宏添加一些功能。 This particular macro finds a specific text "#code_bar#" in an existing MS Word document and replaces it with a different text ie 3541589479 .这个特定的宏在现有的 MS Word 文档中查找特定文本“#code_bar#”,并将其替换为不同的文本,即3541589479 。
Now, once this text is found and replaced (which the macro is already doing correctly), it is meant to change the font to "Free 3 of 9 Extended",which is already imported into Word.现在,一旦找到并替换了此文本(宏已经正确执行了此操作),就可以将字体更改为“Free 3 of 9 Extended”,该字体已经导入到 Word 中。
This is the code, which is working properly except the part where I try to change the font and the size, which is actually not taking place.这是代码,除了我尝试更改字体和大小的部分之外,它工作正常,实际上并没有发生。 Could anyone help?有人可以帮忙吗? Thanks.谢谢。
Public Function sustituirCodigoBarras(codigo_barras)
Dim codigoDeBarras As String
Set codigoBarras = ActiveDocument.Content
'#barras_pedido# codigo de barras del pedido
codigoDeBarras = "#code_bar#"
With obj_Word.ActiveWindow.Selection.Find
.Text = codigoDeBarras
.Replacement.Text = "*" & codigo_barras & "*"
.Replacement.Font.Name = "Free 3 of 9 Regular"
.Replacement.Font.Size = 34
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
End With
End Function
After some extra digging and a good-night sleep here's the answer:经过一些额外的挖掘和睡个好觉后,答案如下:
Rookie mistake.菜鸟失误。
Hope this can help someone else希望这可以帮助别人
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.