PDA

View Full Version : add a row msg box in table w/password protect



blair
09-21-2009, 06:15 PM
I'm trying to setup a macro code for a word template for work. I have a
table w/some columns and rows w/titles. I have inserted a messages box
asking "Insert Another Row?" and If yes is clicked, another row is added and
the field codes are automatically entered blank in the row.
If no is clicked
then it goes to the next field in the next section (not in that table or row). Okay, this works until I try to add: password protected feature. The template needs to be password protected.
Alone on it's self, I know how to do this but the code combined w/this macro
is causing me difficulty. I have tried several things and it's not working.
I have some code in here from a regular unprotect w/out needing a
password and I'm not sure if this is causing problems, but I've tried
removing but still get errors.
I'm not sure what I'm doing wrong. What
does happen is that I'm able to get the message box, but when I click on yes to add antoher row, it goes to the next field and does not add another row.
What am I missing? Can anyone help me? Please. Here is my code.
Also, is there a way that when it's done spellchecking only the form fields that it says that it's done. I don't think mine only does the form field and it definitely doesn't say that it's done (of course this is when it's not password protected). I'm using 2003.

________________________________
Sub SpellCheckForm()
Dim i As Integer
Dim bProtected As Boolean
Dim sPassword As String
'***************************
'Password to unprotect
sPassword = "smilingcat"
'***************************
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=sPassword
End If

'check each formfield for spelling
For i = 1 To ActiveDocument.FormFields.Count
ActiveDocument.FormFields(i).Select

#If VBA6 Then
Selection.NoProofing = False
#End If

Selection.LanguageID = wdEnglishUS
Selection.Range.CheckSpelling
Next

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, _
Noreset:=True, _
Password:=sPassword

End If
End Sub
Public Sub MAIN()
Dim PROT
On Error GoTo -1: On Error GoTo BYE
' NOTE: this is the code for copy

WordBasic.BeginDialog 300, 80, "Insert Another Row?"
WordBasic.GroupBox 10, 6, 275, 41, "Insert Another Row?"
WordBasic.OptionGroup "OptionGroup1"
WordBasic.OptionButton 20, 23, 65, 16, "&Yes", "OptionButton1"
WordBasic.OptionButton 83, 23, 80, 16, "&No", "OptionButton2"
WordBasic.OKButton 12, 54, 88, 21

WordBasic.EndDialog
Dim rowadd As Object: Set rowadd = WordBasic.CurValues.UserDialog
WordBasic.Dialog.UserDialog rowadd

ActiveDocument.Unprotect ("smilingcat")
PROT = 1
If rowadd.optiongroup1 = 0 Then
WordBasic.StartOfRow
WordBasic.EndOfColumn
WordBasic.TableSelectRow
Else
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Tables(1).Select
Selection.Copy

Selection.EndKey Unit:=wdLine
Selection.EndKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
Selection.Paste

WordBasic.TableSelectRow

End If
WordBasic.EditCopy
WordBasic.EditPaste
WordBasic.StartOfRow
Selection.SelectRow
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleSingle

Selection.MoveRight Unit:=wdCell
CommandBars("Forms").Visible = True
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.MoveRight Unit:=wdCell
Selection.FormFields.Add Range:=Selection.Range, Type:= _
wdFieldFormTextInput
Selection.PreviousField.Select
With Selection.FormFields(1)
.Name = "Text4"
.EntryMacro = ""
.ExitMacro = "Module9.MAIN"
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
With .TextInput
.EditType Type:=wdRegularText, Default:="", Format:=""
.Width = 0

CommandBars("Forms").Visible = False

End With
End With
WordBasic.StartOfRow

BYE:
If PROT = 1 Then
WordBasic.ToolsProtectDocument Type:=2, Noreset:=1
Activesheet.Protect ("smilingcat")
End If
End Sub

Tinbendr
09-21-2009, 07:25 PM
[drama:on]
"Wordbasic!!! I'm too scared to run. AAHHHHHhhhhh!! It got me!!!!![drama:off]


Try moving
ActiveDocument.Unprotect ("smilingcat")
To

WordBasic.EndDialog
ActiveDocument.Unprotect ("smilingcat")
Dim rowadd As Object: Set rowadd = WordBasic.CurValues.UserDialog

fumei
09-22-2009, 10:06 AM
1. WordBasic? I have to agree with Tinbendr....aaaaaaggggh! Unless you are dealing with a very old version of Word, drop the WordBasic stuff and use proper VBA. As you state you are using 2003, use VBA, not WordBasic.

2. Try to avoid using Selection. Things like:
Selection.MoveRight Unit:=wdCell
It is better to use objects.

3. Please elaborate on "template". Are you using a .DOT file, and cloning it into a new document (the way templates are supposed to be used)?

fumei
09-22-2009, 10:06 AM
1. WordBasic? I have to agree with Tinbendr....aaaaaaggggh! Unless you are dealing with a very old version of Word, drop the WordBasic stuff and use proper VBA. As you state you are using 2003, use VBA, not WordBasic.

2. Try to avoid using Selection. Things like:
Selection.MoveRight Unit:=wdCell
It is better to use objects.

3. Please elaborate on "template". Are you using a .DOT file, and cloning it into a new document (the way templates are supposed to be used)?

fumei
09-22-2009, 10:13 AM
1. WordBasic? I have to agree with Tinbendr....aaaaaaggggh! Unless you are dealing with a very old version of Word, drop the WordBasic stuff and use proper VBA. As you state you are using 2003, use VBA, not WordBasic.

2. Try to avoid using Selection. Things like:
Selection.MoveRight Unit:=wdCell
It is better to use objects.

3. Please elaborate on "template". Are you using a .DOT file, and cloning it into a new document (the way templates are supposed to be used)?

fumei
09-22-2009, 10:15 AM
What the heck happened there?