【转载】[VBS]去除WORD文档限制编辑

发布时间:2024-11-27 04:28

Word文档编辑:输入文字后按Enter换行,Ctrl+Z撤销,Ctrl+Y重做 #生活常识# #日常生活技巧# #基础电脑操作#

最新推荐文章于 2024-06-05 15:44:52 发布

rsice 于 2020-01-17 13:45:46 发布

Usage:
手动:选中Word文档拖拽到VBS文件上(支持拖拽多个)。
命令行:Cscript -nologo VBS路径 Word文档1 Word文档2 ... 

Rem Code By 老刘

Rem 转载请标明作者

Option Explicit

Const wdNewBlankDocument = 0

Const wdFormatXMLDocument = 12

Const wdFormatFlatXML = 19

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")

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

WScript.Echo "老刘的提醒:由于要保证处理速度(开关WORD太费时),不使用时请手动退出WORD。"

网址:【转载】[VBS]去除WORD文档限制编辑 https://www.yuejiaxmz.com/news/view/286549

上一篇:Matlab与python
下一篇:nslookup用法

相关内容

Word文档图片插入与编辑技巧:版权、格式与高级操作
如何通过简单方法清除Word文档中的多余格式?
如何在Word中编辑图片里的文字:实用技巧指南
WPS Word文档空白页删除指南:快速清除技巧
批量处理Word文档图片的终极指南
压力管理团体方案microsoft word 文档
节能管理制度汇编.doc
[极简主义生活]极简主义的事例(Word可编辑版).doc
个人成长规划word版本.doc
=毕业论文(可编辑) .doc

随便看看