Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 05-28-2024, 08:45 PM
Guessed's Avatar
Guessed Guessed is offline Copy/Paste of unmodified VBA Code in Word returns an error Windows 10 Copy/Paste of unmodified VBA Code in Word returns an error Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Code to copy data from two sheet ,paste into corresponding sheet through cmdbutton jackfruit88 Excel Programming 1 07-08-2022 09:27 PM
paste returns the wrong not the latest cut Peborgh Word 2 11-23-2021 03:31 AM
Copy/Paste of unmodified VBA Code in Word returns an error Error 4605 while trying to copy and paste with same document Ilmari Word VBA 2 05-05-2020 12:08 AM
Copy/Paste of unmodified VBA Code in Word returns an error Copy/Paste error stuart255 Office 5 05-06-2019 02:13 AM
VBA Newbie (Trying to write a code to copy and paste info from one sheet to another) Forum2000s Excel Programming 2 05-07-2017 04:51 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:57 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft