- 帖子
- 1000
- 积分
- 1789
- 技术
- 205
- 捐助
- 50
- 注册时间
- 2016-4-17
|
本帖最后由 老刘1号 于 2019-10-28 14:19 编辑
手动:选中Word文档拖拽到VBS文件上(支持拖拽多个)。
命令行:Cscript -nologo VBS路径 Word文档1 Word文档2 ...
上色工具:http://www.bathome.net/thread-47323-1-1.html
以下为VBS:
Rem Code By 老刘
Rem 转载请标明作者
Option Explicit
Const wdNewBlankDocument = 0 '空白新文档
Const wdFormatXMLDocument = 12 '.DOCX
Const wdFormatFlatXML = 19 '.XML
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim objXmlDom
Set objXmlDom = CreateObject("Microsoft.XMLDOM")
Dim objWord
On Error Resume Next
Set objWord = GetObject(,"Word.Application") '已有word运行则直接得到对象
If Err.Number <> 0 Then
Err.Clear
Set objWord = CreateObject("Word.Application")
If Err.Number <> 0 Then
If UCase(fso.GetBaseName(WScript.FullName)) = "CSCRIPT" Then
WScript.StdErr.WriteLine "老刘的温馨提示:Word的COM自动化组件无法创建!"
Else
MsgBox "Word的COM自动化组件无法创建!",vbQuestion,"老刘的温馨提示"
End If
WScript.Quit 1
End If
End If
On Error Goto 0
Dim objWordDocument,strArg,objXmlDocument,objProtecctionNodes,objProtecctionNode
For Each strArg In WScript.Arguments
Rem 文档→XML。
With objWord
Set objWordDocument = fso.GetFile(strArg)
.ChangeFileOpenDirectory objWordDocument.ParentFolder & "\"
.Documents.Open objWordDocument.Name, False, True
.ChangeFileOpenDirectory Fso.GetSpecialFolder(2) & "\"
.ActiveDocument.SaveAs2 _
fso.GetBaseName(objWordDocument.Path)&".XML", _
wdFormatFlatXML
.ActiveDocument.Close
Set objXmlDocument = _
fso.GetFile( _
fso.GetSpecialFolder(2) & "\" & _
fso.GetBaseName(objWordDocument.Path) & ".XML" _
)
End With
Rem 去除w:documentProtection节点。
With objXmlDom
.load objXmlDocument.Path
Set objProtecctionNodes = .getElementsByTagName("w:documentProtection")
If objProtecctionNodes.length = 0 Then
If UCase(fso.GetBaseName(WScript.FullName)) = "CSCRIPT" Then
WScript.StdErr.WriteLine objWordDocument.Name&" 未被限制编辑"
End If
Else
For Each objProtecctionNode In objProtecctionNodes
objProtecctionNode.parentNode.removeChild(objProtecctionNode)
Next
End If
.save objXmlDocument.Path
.abort
End With
Rem XML→DOCX。
With objWord
.Documents.Open objXmlDocument.Name
.ChangeFileOpenDirectory objWordDocument.ParentFolder & "\"
.ActiveDocument.SaveAs2 _
"[Unlocked]"&fso.GetBaseName(objWordDocument.Path)&".DOCX", _
wdFormatXMLDocument
.ActiveDocument.Close
objXmlDocument.Delete True
End With
Next
objWord.Visible = True
Set fso = Nothing
Set objXmlDom = Nothing
Set objWord = Nothing '该操作不会关闭Word
WScript.Echo "老刘的提醒:由于要保证处理速度(开关WORD太费时),不使用时请手动退出WORD。" |
-
1
评分人数
-
|