Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Word 97 VBA - inserting text

Posted on 1999-07-28
Medium Priority
Last Modified: 2010-04-30
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

Question by:Robertsa
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

RichW earned 300 total points
ID: 1527911
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.


Author Comment

ID: 1527912
Thank you

Expert Comment

ID: 1527913
You're very welcome.  

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question