View Single Post
 
Old 05-30-2018, 03:22 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

No - the 'UpdateBookmark' needs to be a separate sub - you now have one sub inside another.
Code:
Private Sub CommandButton1_Click()
Dim i As Long, StrOut As String
For i = 0 To ListBox1.ListCount - 1
  If ListBox1.Selected(i) Then
    StrOut = StrOut & ListBox1.List(i) & vbCr
  End If
Next i
Call UpdateBookmark("bm1", StrOut)
End Sub

Sub UpdateBookmark(StrBkMk As String, StrTxt As String)
Dim BkMkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(StrBkMk) Then
    Set BkMkRng = .Bookmarks(StrBkMk).Range
    BkMkRng.Text = StrTxt
    .Bookmarks.Add StrBkMk, BkMkRng
  End If
End With
Set BkMkRng = Nothing
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote