我有一个工具,我从网络上的其他地方修改,以使用当前的2021 MS Word Visual Basic应用程序(v7.1)。它基本上是Word文档的批量密码删除工具。
这段代码只是在一个目录中打开所有文件,假设它们具有相同的密码,然后将它们保存到另一个目录中,并删除密码。
但是它在SaveAs
行失败,
运行时错误6294.
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim strPassword As String
strPassword = "current_password"
PathToUse = "C:source"
SavePath = "C:destination"
myFile = Dir$(PathToUse & "*.docx")
While myFile <> ""
'Open document
Set myDoc = Documents.Open(FileName:=PathToUse & myFile, PasswordDocument:=strPassword)
myDoc.SaveAs SavePath & myFile, Password = ""
myDoc.Close
'Next file in folder
myFile = Dir$()
Wend
请试试
myDoc.SaveAs FileName:=SavePath & myFile, Password:=""
SaveAs
方法需要参数。其中一些是Optional
,但如果你需要一些,它们必须按上述建议的方式使用。