View Single Post
 
Old 05-28-2024, 08:45 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Greg

Making a collection seems like extra effort when we could use the Bookmarks.Exists instead.
Code:
Sub AnotherWay()
  Dim aCell As Cell, oRng As Range, strBMName As String
  For Each aCell In Selection.Range.Cells
    If aCell.ColumnIndex = 1 Then
      Set oRng = aCell.Range
      oRng.End = oRng.End - 1
      strBMName = fcnValidateBMName(Trim(oRng.Text))  'needs Greg's function
      If Not ActiveDocument.Bookmarks.Exists(strBMName) Then
        ActiveDocument.Bookmarks.Add strBMName, oRng
      End If
    End If
  Next aCell
End Sub
I didn't include the cell shading where a bookmark already exists because it would need a bit more code to figure out if the selected cell has already been bookmarked from an earlier run.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote