Preventing a macro from clearing form fields

B

Big Al

I have created a form with a macro. The macro cuts and pastes some of the
fields when the user needs to add extra data e.g. another person name. The
macro unprotects the document copies and pastes then re-protects. However if
the user enters the details in the form in the first section, runs the macro
to add extra fields, it clears all the existing data from the fields. How do
I stop that?

The code I wrote is:
Sub AddEmployee()
'
' AddEmployee Macro
' Macro recorded 26/11/2007 by MATHISOA
' If document is protected, Unprotect it.
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""

End If
Selection.MoveUp Unit:=wdLine, Count:=4, Extend:=wdExtend
Selection.Copy
Selection.MoveDown Unit:=wdLine, Count:=4
Selection.PasteAndFormat (wdPasteDefault)

'ReProtect the document.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect wdAllowOnlyFormFields
End If

End Sub
 
G

Greg Maxey

Al,

You already know that the document is unprotected when you get around to
protecting it, so just use:

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top