Script for changing fonts in a Word document

前端 未结 3 1705
粉色の甜心
粉色の甜心 2021-01-24 10:44

I have a Word 2007 file and I want to change all usage of the Courier New font into a Lucida Console font. I need a script that find all words formatted in that font and change

3条回答
  •  执念已碎
    2021-01-24 11:23

    Inside Word, you can record a macro by doing it yourself. Then you open the VBA editor, optionally remove some useless thing (usually too many selections or moves within the file) and you've got your script.

    Edited: moved the contents of a comment here, to answer the author's comment.

    When recording the macro, within the find and replace dialog, click on 'Replace All'. Then stop recording. The generated macro looks like:

    Selection.Find.ClearFormatting 
    Selection.Find.Replacement.ClearFormatting 
    With Selection.Find 
      .Text = "tarte au pomme" 
      .Replacement.Text = "t aux pruneaux" 
      .Wrap = wdFindContinue 
      .MatchCase = False 
      ' removed some stuff 
    End With 
    Selection.Find.Execute Replace:=wdReplaceAll 
    

    From that, you can create the VBScript macro. You need to get the value of wdReplaceAll and wdFindContinue in the Object Browser.

提交回复
热议问题