Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2003 - Macro Code Not Allowing Save on Protected Form.

Status
Not open for further replies.

Pompie1999

Technical User
Jan 22, 2008
6
US
We currently have some very old Word documents that have Macro's (or VB Code) that was written in the 90's. The code has been automatically updated as we've moved to newer versions of Word. These are forms that were created just strictly to be printed out and filled in by hand, so they don't have any of the 'form' features on them.

I have upgraded the forms so that they now have text boxes, check boxes, etc. that would allow the forms to be printed and filled in -- or filled in on-line.

When I click on the 'lock' icon to protect the form, and then try to save the document, I get the error message: "Run-Time error '509': The ToolsRevisions command is not available because the document is a protected document." Then, when I click 'OK' -- it displays the scripts with the 'ISOInfo' code on top and the cursor is on the line talking about ToolsRevisions.

I have to keep the code on the documents because it performs some updates for our ISO system.

How can I upgrade the code so that it will allow me to change these documents to regular forms and save them as protected documents. The code follows.

Dim Path$

Public Sub MAIN()
Dim RMStatus
Dim Nview
Dim Oview
Dim Pview
Dim File$
Path$ = ""

Dim TRdlg As Object: Set TRdlg = WordBasic.DialogRecord.ToolsRevisions(False)
WordBasic.CurValues.ToolsRevisions TRdlg

RMStatus = TRdlg.MarkRevisions
WordBasic.ToolsRevisions MarkRevisions:=0

Nview = WordBasic.ViewNormal()
Oview = WordBasic.ViewOutline()
Pview = WordBasic.ViewPage()

WordBasic.ViewNormal

Start_It:

WordBasic.BeginDialog 470, 214, "Controlled Document Info", "ISOInfo.ISOInfoDialog"
WordBasic.Text 8, 8, 207, 13, "Enter the document control", "Text1"
WordBasic.Text 8, 24, 192, 13, "details for this document:", "Text2"
WordBasic.OKButton 338, 8, 120, 24
WordBasic.CancelButton 338, 38, 120, 24
WordBasic.Text 8, 64, 40, 13, "Title:"
WordBasic.TextBox 8, 80, 450, 18, "Title"
WordBasic.Text 8, 104, 132, 13, "Revision number:"
WordBasic.TextBox 8, 120, 120, 18, "RevNumber"
WordBasic.Text 200, 104, 113, 13, "Effective date:"
WordBasic.TextBox 200, 120, 180, 18, "EffDate"
WordBasic.Text 200, 140, 104, 13, "mmm dd, yyyy"
WordBasic.Text 8, 144, 84, 14, "Written by:"
WordBasic.TextBox 8, 160, 450, 18, "Author"
WordBasic.Text 8, 192, 137, 13, "Document number", "DocNum"
WordBasic.EndDialog

Dim TestDialog As Object: Set TestDialog = WordBasic.CurValues.UserDialog

Dim dlg As Object: Set dlg = WordBasic.DialogRecord.FileSummaryInfo(False)
WordBasic.CurValues.FileSummaryInfo dlg

Path$ = dlg.Directory
File$ = dlg.FileName
If LCase(Left(Path$, 3)) = "r:\" Then
Path$ = Right(Path$, 8) + "\" + Left(File$, (InStr(File$, ".") - 1))
WordBasic.FileSummaryInfo Keywords:=Path$
Else
Path$ = dlg.Keywords
End If

WordBasic.FileSummaryInfo Update:=1

WordBasic.CurValues.FileSummaryInfo dlg

TestDialog.Title = dlg.Title
TestDialog.RevNumber = dlg.Subject
TestDialog.EffDate = dlg.Comments
TestDialog.Author = dlg.Author

On Error GoTo -1: On Error GoTo Cancel_it

WordBasic.Dialog.UserDialog TestDialog

If CheckDate(TestDialog.EffDate) = 1 Then GoTo Start_It

WordBasic.FileSummaryInfo Title:=TestDialog.Title
WordBasic.FileSummaryInfo Subject:=TestDialog.RevNumber
WordBasic.FileSummaryInfo Comments:=TestDialog.EffDate
WordBasic.FileSummaryInfo Author:=TestDialog.Author

WordBasic.StartOfDocument

WordBasic.ViewHeader
WordBasic.EditSelectAll
WordBasic.UnlockFields
WordBasic.UpdateFields
WordBasic.LockFields

WordBasic.GoToHeaderFooter
WordBasic.EditSelectAll
WordBasic.UnlockFields
WordBasic.UpdateFields

Rem ShowNextHeaderFooter
Rem EditSelectAll
Rem UnlockFields
Rem UpdateFields()

Rem GoToHeaderFooter
Rem EditSelectAll
Rem UnlockFields
Rem UpdateFields()
Rem LockFields

WordBasic.CloseViewHeaderFooter

WordBasic.EditSelectAll
WordBasic.UnlockFields
WordBasic.UpdateFields
WordBasic.LockFields

WordBasic.StartOfDocument

WordBasic.Insert Path$
WordBasic.Insert Chr(9) + TestDialog.RevNumber
WordBasic.Insert Chr(9) + TestDialog.Title
WordBasic.Insert Chr(9) + TestDialog.Author
WordBasic.Insert Chr(9) + TestDialog.EffDate

WordBasic.StartOfDocument 1
WordBasic.EditCut

WordBasic.ToolsRevisions MarkRevisions:=RMStatus

Cancel_it:

If Nview = -1 Then WordBasic.ViewNormal
If Oview = -1 Then WordBasic.ViewOutline
If Pview = -1 Then WordBasic.ViewPage

End Sub


'*****************************************************************
Rem This Function Checks the eff date for this format mmm dd, yyyy
Private Function CheckDate(EffDate$)

If Len(EffDate$) <> 12 Then GoTo Problems

Rem CHECK FOR SPACES
If (Mid(EffDate$, 4, 1) <> " " Or Mid(EffDate$, 8, 1) <> " ") Then GoTo Problems

Rem CHECK FOR COMMA
If (Mid(EffDate$, 7, 1)) <> "," Then GoTo Problems

Rem CHECK FOR DAY OF MONTH
If (WordBasic.Val(Mid(EffDate$, 5, 2)) < 1 Or WordBasic.Val(Mid(EffDate$, 5, 2)) > 31) Then GoTo Problems

Rem CHECK FOR YEAR
If (WordBasic.Val(WordBasic.[Right$](EffDate$, 4))) < 1990 Then GoTo Problems

If (Mid(EffDate$, 7, 3)) <> "JAN" Or (Mid(EffDate$, 7, 3)) <> "FEB" Then GoTo Bye
If (Mid(EffDate$, 7, 3)) <> "MAR" Or (Mid(EffDate$, 7, 3)) <> "APR" Then GoTo Bye
If (Mid(EffDate$, 7, 3)) <> "MAY" Or (Mid(EffDate$, 7, 3)) <> "JUN" Then GoTo Bye
If (Mid(EffDate$, 7, 3)) <> "JUL" Or (Mid(EffDate$, 7, 3)) <> "AUG" Then GoTo Bye
If (Mid(EffDate$, 7, 3)) <> "SEP" Or (Mid(EffDate$, 7, 3)) <> "OCT" Then GoTo Bye
If (Mid(EffDate$, 7, 3)) <> "NOV" Or (Mid(EffDate$, 7, 3)) <> "DEC" Then GoTo Bye

Problems:
WordBasic.MsgBox "DATE FORMAT IS NOT VALID -- MMM DD, YYYY"
CheckDate = 1

Bye:

End Function

Private Function ISOInfoDialog(ControlID$, Action, SuppValue)
Dim KeepDisplayed

KeepDisplayed = 0

If Action = 1 Then
WordBasic.[DlgText$] "DocNum", Path$
KeepDisplayed = 1
End If

ISOInfoDialog = KeepDisplayed

End Function
 
Hi Pompie,

The code should work OK if you delete the lines:
Dim TRdlg As Object: Set TRdlg = WordBasic.DialogRecord.ToolsRevisions(False)
WordBasic.CurValues.ToolsRevisions TRdlg

RMStatus = TRdlg.MarkRevisions
WordBasic.ToolsRevisions MarkRevisions:=0

and

WordBasic.ToolsRevisions MarkRevisions:=RMStatus

IMHO, your document and its macros would benefit from being updated from the obsolete WordBasic paradigm to Word 97-2003 formfields and, where necessary, vba. For example, your CheckDate sub tests whether a particular field has had a date entered correctly. Word 97-2003 formfields can be configured to do that with no code, plus they'll convert the date format automatically, rather than requiring the user to input the extra characters required for a long date format, for example.

Cheers

[MS MVP - Word]
 
Thank you so very much for the reply. I'm going to try it when I get back to the office on Monday.

I don't know much about these things, so I'm trying to figure it all out. Do you know of a good book or place on the web that I could go to learn more about the forms and fields, etc.

The code that is on the document was written back in the 90's by someone in our IT group. We don't have any IT folks anymore, so it is 'do-it-yourself' time. There are 5-6 different modules on the 'template' for this document and they update document numbers, revision numbers, revision dates, put appropriate headers and footers on the documents- for our ISO system compliance. I'd love to update the code, but have no clue about where to even begin.
 




Pompie1999,

In the future, please post VBA code questions in Forum707.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Pompie,

Just in case you need to keep the revions code, you could insert this beforehand:

Dim Pwd as String
Pwd = "Password"
ThisDocument.Unprotect Pwd

and then, after the line:
WordBasic.ToolsRevisions MarkRevisions:=RMStatus
add:
ThisDocument.Protect wdAllowOnlyFormFields, Noreset:=True, Password:=Pwd

where 'Password' is your real Password.

As for Word form & vba resources, try:

There's also a lot of good info in other forumsm including:

Cheers

[MS MVP - Word]
 
Thanks MACROPOD:
I deleted the lines you suggested above -- and now I am getting a different 509: error. Perhaps this is all beyond changing. It is now saying:
'Run-Time Error 509': The ViewOutline command is not available because the document is a protected document.

It then opens the code and highlights the line that says:
Oview = WordBasic.ViewOutline().

I tried deleting that line just to see what would happen, but then it just went to the next line.
 
Hi Pompie,

WordBasic's not really my forte - MS had abandoned it before I ever got involved in coding.

Did you try the alternative approach I suggested?

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top