How to save macro changes in Read-Only documents?

P

poi

I have over 100 documents that need the same sentence changed in each one.
The documents have the read-only recommended box checked. I ran a batch to
remove the password to modify but it didn't remove the read-only recommend.
So when I run a macro to change the text I get an error. When I ran Debug it
highlighted "myDoc.Close Savechanges:=wdSaveChanges" but I don't know what to
do with that. (I only copy the macros from this great site!)

I am looking for a way to remove the read-only recommended from multiple
documents in a file.

Please help.
Many thanks,
Poi
 
D

Doug Robbins - Word MVP

I think that you need to supply the WritePasswordDocument when you are
opening the document.

Alternatively, you could use SaveAs to save the document with a name to
which you append a suffix and then Close it with a separate command.




--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
G

Graham Mayor

Your comments in the docmanagement were premature? The following should
work. If you have already removed the password(s), leave the password
prompts blank

Sub BatchProcess()
Dim strFileName As String
Dim strPath As String
Dim sPassword1 As String
Dim sPassword2 As String
Dim oDoc As Document
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
sPassword1 = InputBox("Enter Password to open Document")
sPassword2 = InputBox("Enter Password to edit Document")
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , _
"List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" _
Then strPath = strPath + "\"
End With

If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(strPath, 1) = Chr(34) Then
strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
strFileName = Dir$(strPath & "*.doc")

While Len(strFileName) <> 0
Set oDoc = Documents.Open(FileName:=strPath & strFileName, _
PasswordDocument:=sPassword1, _
WritePasswordDocument:=sPassword2)
'
'Do what you want with oDoc
With oDoc
.Password = ""
.WritePassword = ""
.ReadOnlyRecommended = False
.Close SaveChanges:=wdSaveChanges
End With
strFileName = Dir$()
Wend
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

poi

Yes premature, I apologize. And please disregard my reply post to that
thread since you have responded here.

This worked wonderfully!!! I cannot express my gratitude enough...I echo my
original premature comment ;)

Thank you!!!!!!
poi
 
G

Graham Mayor

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top