PDA

View Full Version : [SOLVED:] Unprotect and Protect a document



Eduardo Care
11-06-2015, 05:44 PM
Hello everyone reading this c:,

Im trying to get this code work:


Sub FilePrint() Dim iCnt As Integer
With Application.ActiveDocument
If .ProtectionType <> wdNoProtection Then _
.Unprotect Password:="Conway"
With ActiveDocument
.Styles("Instructions").Font.Hidden = True
Application.ScreenRefresh
Dialogs(wdDialogFilePrint).Show
.Styles("Instructions").Font.Hidden = False
For iCnt = 1 To .FormFields.Count
.FormFields(iCnt).Select
#If VBA6 Then
Selection.NoProofing = False
#End If
Selection.LanguageID = wdEnglishUS
Selection.Range.CheckSpelling
Next
.Protect Type:=wdAllowOnlyFormFields, Noreset:=True, Password:="Conway"
End With
End With
End Sub



All i want to do its unlock the protected document, run a spellcheck, hide certain style of text then finally block the document again with the same password, but im stuck in the final part, which is blocking the document again.

It doesn't show me any error or mistake, after i print, the spellcheck runs properly, the text i want to hide its removed but the document doesn't gets locked, it get stuck in the first page and don't let me write in the document(Not even in the spots it should) unless i remove the password.

Any idea of whats happening?

My code its hella wrong?

Thanks in advance for your time helping me.

gmaxey
11-06-2015, 05:53 PM
Attach the document or a sanitized version.

Eduardo Care
11-06-2015, 06:06 PM
Password of the file:

Conway

gmaxey
11-06-2015, 08:11 PM
Your document wasn't protected for formfields before the code is run but you then protect if for formfields. There are no formfields in the document. Change to:

.Protect wdAllowOnlyReading, True, "Conway"

Eduardo Care
11-06-2015, 09:51 PM
You are totally right, idk how i didnt realize thanks alot Greg you are amazing!