View Single Post
  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default if I know the password, how do I remove it from a large no of docs?

Did you change the lines

Const pwd = "MyPaSsWoRd" ' to be changed
Const pathToOpen = "C:\temp\" ' to be changed
Const pathToSave = "C:\temp1\" ' to be changed

to the actual password and folders to be used? If so, are you sure the value
you assigned to pathToOpen is exactly correct, and is there a backslash at
the end of it? If that path doesn't match the path to an existing folder, or
if the backslash is missing, you'll get that same message as if the path was
right but the folder was empty.

Unfortunately, it's impossible to look inside the built-in Dir$() function
and ask it why it isn't matching anything when you think it should be. You
have to kind of poke around the edges to see if you can spot something odd.
For example, you could declare another string

Dim initFname As String

and then replace the line

fName = Dir$(pathToOpen & "*.doc")

with

initFname = pathToOpen & "*.doc"
fName = Dir$(initFname)

Then you can set a breakpoint (press F9) on the second of those two lines
and run the macro. When it stops at the breakpoint, hover the mouse over the
word initFname to look at the value being passed into Dir$(). Verify that it
matches the folder path, and that it properly has a backslash between the
folder name and the *.doc. Press F8 to execute the breakpointed line, and
look at the resulting value of fName. If everything else is right, it
_should_ contain the name of a doc file in the folder; if it's an empty
string, Dir$() is saying that it didn't find anything at the specified
location.

wrote:
Jay

Thanks very much. The code makes sense to me but when I install and
run it, it doesn't recognize any filenames and terminates at the
MsgBox "No *.doc files in " & pathToOpen". I installed it as a module
and even created a test.doc file with the same password. What am I
missing here?

m|


On Jan 10, 5:13 pm, "Jay Freedman" wrote:
wrote:
Hello


I have a large number of docs (500+) that I need to move to our
company server. They are all encrypted with the same password, and I
know the password, so I don't need a cracker program, but I am
looking for a script or utility that will allow me to remove
password protection from all of these docs at once.


The thought of doing them all one by one is pretty unappealing.
Thanks!


chrs
m|


Use this macro (seehttp://www.gmayor.com/installing_macro.htmif
needed):

Sub demo()
Dim oDoc As Document
Dim fName As String
Const pwd = "MyPaSsWoRd" ' to be changed
Const pathToOpen = "C:\temp\" ' to be changed
Const pathToSave = "C:\temp1\" ' to be changed

fName = Dir$(pathToOpen & "*.doc")
If fName = "" Then
MsgBox "No *.doc files in " & pathToOpen
End If

WordBasic.DisableAutoMacros 1 ' disable any AutoOpen

On Error GoTo FinalExit

While fName ""
Set oDoc = Documents.Open(FileName:=pathToOpen & fName, _
PasswordDocument:=pwd, AddToRecentFiles:=False)
oDoc.SaveAs FileName:=pathToSave & fName, Password:=""
oDoc.Close SaveChanges:=wdDoNotSaveChanges
fName = Dir$()
Wend

Exit Sub

FinalExit:

WordBasic.DisableAutoMacros 0 ' reenable

If Err.Number 0 Then
Select Case Err.Number
Case 5152:
MsgBox "Could not save " & pathToSave & fName
Case Else
MsgBox Err.Number & vbCr & Err.Description
End Select
End If
End Sub

You'll have to enter the real password and the paths to the folders
for the original and "de-passworded" files. The macro could probably
use some more error handling, but this may be sufficient. Note that
it will stop as soon as there's any error and not go on to any more
files; after fixing the problem, remove any files from the source
folder that have already been processed, and then restart the macro.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:
http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.