标题: [问题求助] 这个VBS给WORD取消密码怎么不成功? [打印本页]
作者: ww0000 时间: 2015-1-20 14:39 标题: 这个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.Quit
复制代码
作者: apang 时间: 2015-1-20 20:37
- 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"
复制代码
win7 32bit + ms word 2007 测试正常
作者: ww0000 时间: 2015-1-21 08:21
回复 2# apang
老师,密码不能删除!1
作者: DAIC 时间: 2015-1-21 09:02
回复 3# ww0000
什么操作系统?Office版本呢?
作者: ww0000 时间: 2015-1-21 09:06
回复 4# DAIC
XP系统,Office2003
作者: ww0000 时间: 2015-1-21 09:10
回复 4# DAIC
是不是宏工具里面的工具---引用 没引用? 但加密都可以加的呀!
作者: DAIC 时间: 2015-1-21 09:12
回复 6# ww0000
不清楚,我已经很长时间不使用XP了,没用这样的环境,无法测试。
作者: ww0000 时间: 2015-1-21 09:13
回复 7# DAIC
上面的代码在W7系统测试成功吗?
作者: DAIC 时间: 2015-1-21 09:22
回复 8# ww0000
请看2楼最后一行文字
作者: apang 时间: 2015-1-21 10:09
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"
复制代码
作者: ww0000 时间: 2015-1-21 11:47
回复 10# apang
终于成功,谢谢老师!!
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |