colmguckian
07-07-2011, 02:40 AM
I am modifing a word document from excel
I have created bookmarks which represent each page.
I would like a code which deletes all the pages that contains no underlined text.
Here is what I have so Far
Sub FindUnderlined()
Dim wdApp As Word.Application
Set wdApp = GetObject(, "Word.Application")
wdApp.Visible = True
Dim I As Integer
For I = 1 To Documents("MK").Bookmarks.Count
Documents("MK").Bookmarks("Page" & I).Select
Word.Application.Selection.Find.ClearFormatting
With Word.Application.Selection.Find
.Font.Underline = wdUnderlineSingle
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Word.Application.Selection.Find.Execute
If Word.Application.Selection.Find.Found = False Then
Word.Application.Documents("MK").Bookmarks("Page" & I).Select
Selection.Delete
End If
Next I
End Sub
The code works fine until it gets to the highlighted If Statement
but the If statement does not delete the pages with no underlined text.
I would be greatful for any help
I have created bookmarks which represent each page.
I would like a code which deletes all the pages that contains no underlined text.
Here is what I have so Far
Sub FindUnderlined()
Dim wdApp As Word.Application
Set wdApp = GetObject(, "Word.Application")
wdApp.Visible = True
Dim I As Integer
For I = 1 To Documents("MK").Bookmarks.Count
Documents("MK").Bookmarks("Page" & I).Select
Word.Application.Selection.Find.ClearFormatting
With Word.Application.Selection.Find
.Font.Underline = wdUnderlineSingle
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Word.Application.Selection.Find.Execute
If Word.Application.Selection.Find.Found = False Then
Word.Application.Documents("MK").Bookmarks("Page" & I).Select
Selection.Delete
End If
Next I
End Sub
The code works fine until it gets to the highlighted If Statement
but the If statement does not delete the pages with no underlined text.
I would be greatful for any help