Word 97 VBA - inserting text

I have the following situation which I need assistance with:

I have an option button and if it is not selected, I want to be able to insert a blank space at a bookmark in a document (so information can be manually entered in pen at a later date - so in other words a string of blank characters). I have the following code but it is not working.

Private Sub optEmployerSpons_Empty()
If optEmployerSpons.Value = False Then
Selection.GoTo What:=wdGoToBookmark, Name:="bkDlg_MemberDOB"
Selection.InsertAfter Text:="              "
End If
End Sub

Any assitance would be appreciated.

Thank you

Who is Participating?
RichWConnect With a Mentor Commented:
First I'd like to know which version of Word you're using.  Second, I would try this by using the Find/Replace method.  You would make the bookmark name seen in text and do a find replace.  Set a variable for the blank spaces.

Dim strBlank, strText

strText = "       "

If optEmployerSpons.Value = False then

   With objWord.Selection.Find
      .Text = "mrkBookMarkText"
      .Replacement.Text = strText
      .Execute Replace:=wdReplaceAll, Forward:=True,    Wrap:=wdFindContinue
   End With
End If

This way you can Replace the bookmark field with the blank variable or you can place replace the bookmark field with another variable of text.  You don't have to worry about leading or trailing spaces of blanks with InsertBefore and InsertAfter.

Good luck.

RobertsaAuthor Commented:
Thank you
You're very welcome.  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.