A
aehan
Hello all
I have some code which is supposed to delete data if it contains specific
words. The code I have is as follows:
If ActiveDocument.Bookmarks("test").Range.Words(2) = "Central
Service" Then
With Selection
.GoTo What:=wdGoToBookmark, Name:="test"
.Delete
.GoTo What:=wdGoToBookmark, Name:="test2"
.MoveRight unit:=wdWord, Count:=4, Extend:=wdExtend
.Delete
End With
End If
I have stepped through the code and it fails at the IF clause, so doesn't
run. If, however, I only had one word in the bookmark and amended the if to
read:
If ActiveDocument.Bookmarks("test").Range.Words(1) = "Central" Then
With Selection
.GoTo What:=wdGoToBookmark, Name:="test"
.Delete
.GoTo What:=wdGoToBookmark, Name:="test2"
.MoveRight unit:=wdWord, Count:=4, Extend:=wdExtend
.Delete
End With
End If
the code runs beautifully. I really need to use the two word option, and I
have spent ages trying to work out why it doesn't work when looking for two
words. Can anyone help me and tell me what I've done wrong please?
Thanks in frustration
Aehan
I have some code which is supposed to delete data if it contains specific
words. The code I have is as follows:
If ActiveDocument.Bookmarks("test").Range.Words(2) = "Central
Service" Then
With Selection
.GoTo What:=wdGoToBookmark, Name:="test"
.Delete
.GoTo What:=wdGoToBookmark, Name:="test2"
.MoveRight unit:=wdWord, Count:=4, Extend:=wdExtend
.Delete
End With
End If
I have stepped through the code and it fails at the IF clause, so doesn't
run. If, however, I only had one word in the bookmark and amended the if to
read:
If ActiveDocument.Bookmarks("test").Range.Words(1) = "Central" Then
With Selection
.GoTo What:=wdGoToBookmark, Name:="test"
.Delete
.GoTo What:=wdGoToBookmark, Name:="test2"
.MoveRight unit:=wdWord, Count:=4, Extend:=wdExtend
.Delete
End With
End If
the code runs beautifully. I really need to use the two word option, and I
have spent ages trying to work out why it doesn't work when looking for two
words. Can anyone help me and tell me what I've done wrong please?
Thanks in frustration
Aehan