任何人都知道或能够帮助我使用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
下一步
答案 0 :(得分:0)
您应该在程序中添加以下引用:
Microsoft.Office.Interop.Word
Microsoft Office对象库
你可以通过正确的ckick项目来做到这一点 - >添加引用,从GAC选项卡中选择我上面提到的第一个引用,从COM选项卡中选择第二个引用。