Ms word Word 2007脚本随机字体生成器

Ms word Word 2007脚本随机字体生成器,ms-word,Ms Word,是否有人知道或能够帮助我将其用于Word 2007。 这是一个应该随机设置样式的代码段 //Create instance of Word application Set objWord = CreateObject("Word.Application") objWord.Visible = True //Open an existing Word document, Make sure the file is exist in this path- otherwise the program

是否有人知道或能够帮助我将其用于Word 2007。 这是一个应该随机设置样式的代码段

//Create instance of Word application
Set objWord = CreateObject("Word.Application")
objWord.Visible = True

//Open an existing Word document, Make sure the file is exist in this path- otherwise the program fails.
Set objDoc = objWord.Documents.Open("C:\Scripts\Test.doc")

//Create instance of random object
Set objRandom = CreateObject("System.Random")

intLow = 1
intHigh = 5

//Get the text of word document
Set objRange = objDoc.Range()
//Get the charcters of the text
Set colCharacters = objRange.Characters

 //Set different styles randomly 
For Each strCharacter in colCharacters
    intRandom = objRandom.Next_2(intLow,intHigh)

Select Case intRandom
    Case 1 strCharacter.Font.Name = "Arial"
    Case 2 strCharacter.Font.Name = "Times New Roman"
    Case 3 strCharacter.Font.Name = "Courier New"
    Case 4 strCharacter.Font.Name = "Forte"
End Select

接下来

您应该将以下参考添加到程序中:

  • Microsoft.Office.Interop.Word

  • Microsoft Office对象库


  • 您可以通过右键单击project->Add reference,从GAC选项卡选择上面提到的第一个引用,从COM选项卡选择第二个引用。

    有什么问题?它是否适用于早期版本的Word,但不适用于2007?我甚至不知道如何编写脚本。我读了一些脚本文章,并尝试将其插入Word中的VB宏记录器,但它不起作用。我希望有人能很快把它插入到word的那个版本中,让它工作起来,或者找到一个快速解决我做错了什么的方法。我真的不知道这是什么剧本。我明白,如果没有一个快速修复或解决方案,那么我想我只能靠自己了。无论如何谢谢你的回复。