Options.ReplaceSelection

  • Thread starter spunkymuffmonkey
  • Start date
S

spunkymuffmonkey

Hi there,

A user of a form that I have created suggested a change that would make life
easier for them, but I am struggling to achieve what is required.

When the user navigates between text formfields they sometimes accidentally
replace the text that is already present in that formfield.

To prevent this I have tried to utilise the AutoOpen macro to change the
ReplaceSelection option value to False when the document opens, and then
change the value back to True with a Document_Close macro, with very little
success unfortunately, the code I have been using is:

Sub AutoOpen()

Application.Options.ReplaceSelection = False

End Sub

and

Private Sub Document_Close()

Application.Options.ReplaceSelection = True

End Sub

The DocumentClose macro is really the part that is not working, although
when I run this code from the VBeditor it works, but not when I use it as
intended (i.e. when I simply close the document).

Would anybody please spare me the time to point out where I am going wrong,
or even a better way of acheiving what I am after.

Many thanks for looking!
 
H

Helmut Weber

Hi,

try that:

Private Sub Document_Close()
ActiveDocument.Saved = False
Application.Options.ReplaceSelection = True
ActiveDocument.Save
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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