Delete only certain bookmarks (starting with Prefix "Diss_Chapter")

A

andreas

I would like to delete all the bookmarks that start with the prefix
"Diss_Chapter". The other ones I would like to leave alone. How can
this be achieved using Word VBA?

Help is appreciated. Thank you very much in advance.

Regards,

Andreas
 
J

Jean-Guy Marcil

andreas was telling us:
andreas nous racontait que :
I would like to delete all the bookmarks that start with the prefix
"Diss_Chapter". The other ones I would like to leave alone. How can
this be achieved using Word VBA?

Help is appreciated. Thank you very much in advance.

Regards,

Andreas

Try this:

'_______________________________________
Const strBookPrefix As String = "Diss_Chapter"
Dim i As Long

With ActiveDocument.Bookmarks
For i = .Count To 1 Step -1
If Left(.Item(i).Name, 12) = strBookPrefix Then
.Item(i).Delete
End If
Next
End With
'_______________________________________

But if you meant that you not only wanted to delete the bookmarks, but the
text as well, replace

.Item(i).Delete

by

.Item(i).Range.Delete

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Helmut Weber

Hi Andreas,

like this:

Sub Test99992()
Dim oDcm As Document
Dim oBkm As Bookmark
Set oDcm = ActiveDocument
For Each oBkm In oDcm.Bookmarks
If Left(oBkm.Name, 12) = "Diss_Chapter" Then
oBkm.Delete
End If
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
A

andreas

andreas was telling us:
andreas nous racontait que :



Try this:

'_______________________________________
Const strBookPrefix As String = "Diss_Chapter"
Dim i As Long

With ActiveDocument.Bookmarks
For i = .Count To 1 Step -1
If Left(.Item(i).Name, 12) = strBookPrefix Then
.Item(i).Delete
End If
Next
End With
'_______________________________________

But if you meant that you not only wanted to delete the bookmarks, but the
text as well, replace

.Item(i).Delete

by

.Item(i).Range.Delete

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:http://www.word.mvps.org

Jean-Guy,
nice code. It is working fine. Thank you!
 
A

andreas

Hi Andreas,

like this:

Sub Test99992()
Dim oDcm As Document
Dim oBkm As Bookmark
Set oDcm = ActiveDocument
For Each oBkm In oDcm.Bookmarks
If Left(oBkm.Name, 12) = "Diss_Chapter" Then
oBkm.Delete
End If
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"


Helmut,

it is working fine. Thank you. I am not quite sure about the handling
of right answers. Is it sufficent to just rate the answers by clicking
these stars or do you experts need always a written feedback by mail
even if the user is satisfied with your answer.
 
H

Helmut Weber

"Thank you" is quite sufficient and welcome, too.

Ratings are not shown in all newsreaders.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top