返回列表 发帖

[问题求助] 这个VBS给WORD取消密码怎么不成功?

Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Dim objShell,objFolder,FolderPath,pw,wk,EAPP,FSO,FSOFolder,FSOFile
'获取Excel文件所在文件夹路径
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, "Select a folder:", OPTIONS,"")
If objFolder Is Nothing Then
Wscript.Quit
End If
FolderPath =objFolder.Self.Path
PW=Inputbox("请输入密码","批量去除密码")
if len(PW)=0 then Wscript.Quit
Set EAPP=CreateObject("Word.Application")
Set FSO=CreateObject("Scripting.FileSystemObject")
Set FSOFolder=FSO.GetFolder(FolderPath)
For Each FSOFile in FSOFolder.Files
If instr(Fsofile.Name,".doc") then
    Set wk=EAPP.Documents.Open(FSOFile.Path,,,,pw)
    wk.Password=""
    wk.Close True
End If
Next
EAPP.QuitCOPY

回复 10# apang


    终于成功,谢谢老师!!

TOP

objItem.Type 在 office 2003 上显示的字串不一样,算了,还是fso遍历吧
Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, "Select a Folder:", OPTIONS, &h00)
If objFolder is Nothing Then WScript.Quit
strPath = objFolder.Self.Path
strPwd = Inputbox("请输入密码","批量去除密码")
If Len(strPwd) = 0 Then WScript.Quit
Set objWord = CreateObject("Word.Application")
objWord.Visible = true
Set fso = CreateObject("Scripting.FileSystemObject")
For Each file in fso.GetFolder(strPath).Files
        strExt = fso.GetExtensionName(file)
        If LCase(Left(strExt, 3)) = "doc" Then
                Set objDoc = objWord.Documents.Open(file.Path,,,,strPwd)
                objDoc.Password = ""
                objWord.selection.TypeText " "
                objWord.selection.TypeBackSpace
                objDoc.SaveAs file.Path
                objDoc.Close True
        End If
Next
objWord.Quit
MsgBox "OK"COPY
1

评分人数

TOP

回复 8# ww0000


    请看2楼最后一行文字

TOP

回复 7# DAIC


    上面的代码在W7系统测试成功吗?

TOP

回复 6# ww0000


    不清楚,我已经很长时间不使用XP了,没用这样的环境,无法测试。

TOP

回复 4# DAIC


    是不是宏工具里面的工具---引用  没引用? 但加密都可以加的呀!

TOP

回复 4# DAIC


    XP系统,Office2003

TOP

回复 3# ww0000


    什么操作系统?Office版本呢?

TOP

回复 2# apang


    老师,密码不能删除!1

TOP

Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, "Select a Folder:", OPTIONS, &h00)
If objFolder is Nothing Then WScript.Quit
strPath = objFolder.Self.Path
strPwd = Inputbox("请输入密码","批量去除密码")
If Len(strPwd) = 0 Then WScript.Quit
Set objWord = CreateObject("Word.Application")
objWord.Visible = true
Set colItems = objShell.NameSpace(strPath).Items
For Each objItem in colItems
        If Left(objItem.Type,21) = "Microsoft Office Word" Then
                Set objDoc = objWord.Documents.Open(objItem.Path,,,,strPwd)
                objDoc.Password = ""
                objWord.selection.TypeText " "
                objWord.selection.TypeBackSpace
                objDoc.SaveAs objItem.Path
                objDoc.Close True
        End If
Next
objWord.Quit
MsgBox "OK"COPY
win7 32bit + ms word 2007 测试正常

TOP

返回列表