From: macropod on 30 Dec 2009 20:58 Hi Gerry, We seem to have been down this path recently in another forum: Sub RenameBookmarks() Dim BM_Names() Dim i As Long With ActiveDocument For i = 1 To .Bookmarks.Count ReDim Preserve BM_Names(i) BM_Names(i) = .Bookmarks(i).Name Next For i = 1 To .Bookmarks.Count With .Bookmarks(BM_Names(i)) .Range.Bookmarks.Add Name:="NEW_" & .Name, Range:=.Range .Delete End With Next End With End Sub -- Cheers macropod [Microsoft MVP - Word] "Fumei2 via OfficeKB.com" <u53619(a)uwe> wrote in message news:a16116aacd249(a)uwe... >I believe this code will fail. Maybe in 2007 it works, but it certainly does > not work for earlier versions. The .Name property of Bookmarks is read-only. > > You can not change the names of bookmarks. You must use the range of the > bookmark and make a new bookmark (giving the new bookmark the name you want). > You also have to be careful about deleting the old bookmark names because of > the way Word deals with the bookmark collection. It is best to do your > creation of new bookmarks, THEN delete the old ones with something like: > > Sub ChangeBM() > Dim oBk As Bookmark > Dim oBM_Delete() > Dim j As Long > Dim var > > For Each oBk In ActiveDocument.Bookmarks > ' make a new bookmark using SAME range > ActiveDocument.Bookmarks.Add _ > Name:="Test_" & oBk.Name, _ > Range:=oBk.Range > ' add the old name to an array > ReDim Preserve oBM_Delete(j) > oBM_Delete(j) = oBk.Name > j = j + 1 > Next oBk > > ' now delete the old bookmarks > For var = 0 To UBound(oBM_Delete()) > ActiveDocument.Bookmarks(oBM_Delete(var)).Delete > ' note this deletes the bookmark > ' NOT the range > Next > End Sub > > DaveLett wrote: >>Hi, >> >>I think you're looking for something like the following: >> >>Dim oBk As Bookmark >> >>For Each oBk In ActiveDocument.Bookmarks >> oBk.Name = "Test_" & oBk.Name >>Next oBk >> >>HTH, >>Dave > > -- > Message posted via OfficeKB.com > http://www.officekb.com/Uwe/Forums.aspx/word-programming/200912/1 >
From: DaveLett on 31 Dec 2009 08:49 Hi Greg, Yes. Well, that's embarrassing. Mea culpa. "Greg Maxey" wrote: > Dave, > > Does that not generate a compile error. Can't assign to read only property? > > > "DaveLett" <DaveLett(a)discussions.microsoft.com> wrote in message > news:7456D0B6-728C-4B94-9EBA-69751F441A85(a)microsoft.com... > > Hi, > > > > I think you're looking for something like the following: > > > > Dim oBk As Bookmark > > > > For Each oBk In ActiveDocument.Bookmarks > > oBk.Name = "Test_" & oBk.Name > > Next oBk > > > > HTH, > > Dave > > > . >
First
|
Prev
|
Pages: 1 2 Prev: Where can I find information about word htm styles Next: Word to Jpeg conversion |