ActiveDocument.Bookmarks().Range.InsertBefore not working as expected in MSWord UseForm

Why oh why, does the below ActiveDocument.Bookmarks().Range code;  

1) add an empty line before the inserted text
2) does not bullet the second insert
3) keeps the bookmark on the first line (shouldn't it have inserted "before" the bookmark?)

HELP!!!!
'CHECK REQUIREMENTS
If IsEmpty(Me.lbRequirements.Text) Then
    ' Do Nothing
Else
    Dim x As Long
    'Cylcle through each item in the listindex
    For x = 1 To Me.lbRequirements.ListCount - 1
        'If the item is selected add it to the document with a line return
        If Me.lbRequirements.Selected(x) Then
            ActiveDocument.Bookmarks("Requirements").Range.InsertBefore lbRequirements.List(x)
            ActiveDocument.Bookmarks("Requirements").Range.ListFormat.ApplyBulletDefault
            ActiveDocument.Bookmarks("Requirements").Range.InsertParagraph
        End If
    Next x
End If

Open in new window

Results of insert Results of insert
DahriaAsked:
Who is Participating?
 
GrahamSkanRetiredCommented:
1.  This code line creates the empty document line
    ActiveDocument.Bookmarks("Requirements").Range.InsertParagraph

2. According to your pictures it does bullet the second line

3. I would add text and in a paragraph like this:

ActiveDocument.Bookmarks("Requirements").Range.InsertBefore lbRequirements.List(x) & VbCr




 
0
 
DahriaAuthor Commented:
Thank-y:o)u Graham,

1)  I removed the ActiveDocument.Bookmarks("Requirements").Range.InsertParagraph

2)  Was refering to the second "insert".  There are three inserts from the "Requirements" array;  Beneficiary Designation, Notarized Will Searches and Notarized Will.  The second insert... Notarized Will Searches is still not bulletted. (see new image attached)

3)  Added the "& VbCr"  after the InsertBefore to create new line

 New inserts New inserts
0
 
DahriaAuthor Commented:
Aaaaahhhh... found the solution to issue 2)...

I removed the bullet formatting from the code and applied it directly to the template.  This then includes the vbCR for the first "inserted" line only.  So added a If/Else check for the first insert and applied vbCR to all subsequent inserts. (see below code snippet)

 
'CHECK REQUIREMENTS
If IsEmpty(Me.lbRequirements.Text) Then
    ' Do Nothing
Else
    Dim x As Long
    Dim z As Long
    'Cylcle through each item in the listindex
    For x = 0 To Me.lbRequirements.ListCount - 1
        'If the item is selected add it to the document with a line return
        If Me.lbRequirements.Selected(x) Then
            If z = 0 Then
                ActiveDocument.Bookmarks("Requirements").Range.InsertAfter lbRequirements.List(x)
                z = 1
            Else
                ActiveDocument.Bookmarks("Requirements").Range.InsertAfter lbRequirements.List(x) & vbCr
            End If
        End If
    Next x
End If

Open in new window


Thank-you again Graham for pointing me in the right direction.

:o)
0
 
GrahamSkanRetiredCommented:
If that works, go with it.

It wasn't easy to see exactly where you were starting from (Picture.Value < 1000Words.Value), or what the full objective was.
0
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.