VBS读取word文档书签中的内容
想用vbs 读取word文档文本框中的内容,一个文档中有多个带书签的文本框,如何用vbs把其书签的内容赋值给变量,要处理的WORD文档在附件中
先谢谢了,希望能给个示例程序
[解决办法]
我看了你的附件,全部书签都定义为文本框是吧?读取“bookmark15”书签文本内容的示例如下:
Set oApp = CreateObject("Word.Application") Set oDoc = oApp.Documents.Open ("D:\\temp\\651.doc") oText = oDoc.Bookmarks("bookmark15").Range.Sentences(1).Textmsgbox "“bookmark15”书签内的文本是:" & oText,,"文本内容"oDoc.Close
[解决办法]
On Error Goto 0
Dim oApp,oDoc
Set oApp = CreateObject("Word.Application")
Set oDoc = oApp.Documents.Open ("D:\\651.doc")
oText = oDoc.Bookmarks("bookmark2").Range.Sentences(1).Text
msgbox "书签内的文本是:" & oText,,"文本内容"
oDoc.Close
set oApp = nothing
set oDoc = nothing
[解决办法]
更新
On Error Goto 0
Dim oApp,oDoc,ws
Set oApp = CreateObject("Word.Application")
Set oDoc = oApp.Documents.Open ("D:\\651.doc")
set ws=createobject("wscript.shell")
oText = oDoc.Bookmarks("bookmark12").Range.Sentences(1).Text
msgbox "书签内的文本是:" & oText,,"文本内容"
oDoc.Close
ws.run "cmd /c taskkill /f /im WINWORD.EXE",0 '关闭WINWORD.EXE进程
set oApp = nothing
set oDoc = nothing