|
Visual Basic (VB6 and VBA) |
|
Copyright 1999-2001 Christopher Greaves. All rights reserved. Home Page and email to [email protected] |
| If in doubt, record a macro and inspect the entrails! |
Visual Basic Library
This page was last updated on Saturday, November 24, 2001
Public Function blnBookMarkText(strBookMark As String, strText As String) As Boolean ' Procedure : blnBookMarkText ' Description: Delete the existing bookmark and data, if it exists, and replace it at the end of the document. ' Copyright: Chris Greaves Inc. ' Inputs: STRING bookmark identifier, STRING text to be inserted. ' Returns: TRUE if the bookmark previously existed. ' Assumes: None. ' Side Effects: None. ' Tested: By the calls shown below. ' First delete an existing version of the bookmarked text If ActiveDocument.Bookmarks.Exists(strBookMark) Then blnBookMarkText = True ActiveDocument.Bookmarks(strBookMark).Select Selection.Delete Else blnBookMarkText = False End If ' Second, goto the end of the document Selection.EndKey unit:=wdStory, Extend:=wdMove ' Insert the string, and bookmark the text Dim lngStart, lngEnd As Long lngStart = Selection.Start Selection.TypeText (strText) Selection.TypeParagraph lngEnd = Selection.End ActiveDocument.Range(Start:=lngStart, End:=lngEnd).Select ActiveDocument.Bookmarks.Add Name:=strBookMark, Range:=Selection.Range Selection.Collapse 'Sub TESTBookMarkText() ' MsgBox blnBookMarkText("alpha", "Delete the existing bookmark") ' MsgBox blnBookMarkText("alpha", "Delete the existing bookmark") ' always TRUE on the second call ' MsgBox blnBookMarkText("beta", "if it exists") ' MsgBox blnBookMarkText("gamma", "the end of the document") 'End Sub End Function
| We all knew nothing when we started … |
|
Home Page and Contact Information Send email to [email protected]. This page was last updated Monday, November 19, 2001 |