Find End Of Document using Word VBA
Most often when we loop through the document, we need to know the End of Word Document. We can achieve that by using Bookmarks
Sub Drive_IS_EOD()
If IS_EOD(Selection.Range) = True Then
MsgBox "End of Document"
Else
MsgBox "Miles to Go:)"
End If
End Sub
The function below uses the Exists method to check if the bookmark exist in the specified range
Function IS_EOD(ByRef MRange As Range) As Boolean
If MRange.Bookmarks.Exists("\EndOfDoc") = True Then
IS_EOD = True
End If
End Function
\EndOfDoc is a predefined bookmark, which is used here
Showing posts with label Word VBA Exists Method. Show all posts
Showing posts with label Word VBA Exists Method. Show all posts
Monday, March 31, 2008
Check Existence of BookMark using VBA (Word VBA)
Find BookMarks using VBA
BookMarks are vital in Word. However, when you look for a particular bookmark using VBA, it will cease to exist causing 5101 - This bookmark does not exist error.
To avoid this it is better to use Exists Method to check if the Bookmark exist.
Sub Check_If_BookMark_Exists()
If ActiveDocument.Bookmarks.Exists("TempBKMK") = True Then
ActiveDocument.Bookmarks("TempBKMK").Range.Text = "Something"
End If
End Sub
Exists method determines whether the specified bookmark or task exists. Returns True if the bookmark or task exists
BookMarks are vital in Word. However, when you look for a particular bookmark using VBA, it will cease to exist causing 5101 - This bookmark does not exist error.
To avoid this it is better to use Exists Method to check if the Bookmark exist.
Sub Check_If_BookMark_Exists()
If ActiveDocument.Bookmarks.Exists("TempBKMK") = True Then
ActiveDocument.Bookmarks("TempBKMK").Range.Text = "Something"
End If
End Sub
Exists method determines whether the specified bookmark or task exists. Returns True if the bookmark or task exists
Subscribe to:
Posts (Atom)
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.