From: jkriordan on 30 Dec 2009 15:31 Can anybody tell me how to search and replace the names of bookmarks in a Word 07 docx? Halfway into a very large document, I figured out a very useful naming scheme. Now I want to revise the names earlier bookmarks without redoing each one individual.
From: DaveLett on 30 Dec 2009 15:58 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
From: Greg Maxey on 30 Dec 2009 16:09 The .Name property of a bookmark is "read only." I think the only way you could do this is to cycle through the existing bookmark collection and recreate the bookmarks with the new name. Perhaps something like this: Sub ScratchMaco() Dim i As Long Dim oRng As Word.Range Dim j As Long For j = ActiveDocument.Bookmarks.Count To 1 Step -1 Set oRng = ActiveDocument.Bookmarks(j).Range oRng.Text = ActiveDocument.Bookmarks(j).Range.Text ActiveDocument.Bookmarks.Add "My_new_name" & j, oRng Next End Sub "jkriordan" <jkriordan(a)discussions.microsoft.com> wrote in message news:8D8F650C-689F-41D2-8C1F-B248FE2AB2A8(a)microsoft.com... > Can anybody tell me how to search and replace the names of bookmarks in a > Word 07 docx? > > Halfway into a very large document, I figured out a very useful naming > scheme. Now I want to revise the names earlier bookmarks without redoing > each > one individual.
From: Greg Maxey on 30 Dec 2009 16:11 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
From: Fumei2 via OfficeKB.com on 30 Dec 2009 16:29 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
|
Next
|
Last
Pages: 1 2 Prev: Where can I find information about word htm styles Next: Word to Jpeg conversion |