Pompie1999
Technical User
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
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