PDA

View Full Version : Cell validation on Word Save.



dheeraj
04-02-2007, 09:47 PM
Dear All

I have a requirement to create a word template/file where it should validate presence of a value in a form field on saving of the file.

Is it possible to put this kind of check in a word file to validate presence of a form field or a table cell on saving of a word file.

Thanks in advance.
Dheeraj Nagpal

fumei
04-03-2007, 03:38 AM
Yes.Sub FileSave()
If ActiveDocument.FormFields("TextHere").Result _
= "" Then
Msgbox "Hey! The TextHere field is blank!! " & _
"The file is NOT being saved. Please enter text."
Exit Sub
Else
ActiveDocument.Save wdSaveChanges
End If

If ActiveDocument.Tables(3).Cell(2, 2).Range.Text = _
Chr(13) & Chr(7) Then
Msgbox "Cell(2,2) in table 3 is blank. This cell " & _
"must contain something...anything. " & _
"The file is NOT being saved. Please enter something."
Exit Sub
Else
ActiveDocument.Save wdSaveChanges
End If
End Sub

You stated it as OR - a formfield OR a table cell.

If you wanted to do both (a formfield AND a table cell) you would need to change the code a little bit.