Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Can anyone change this VBA Code to my required way?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Narayana Reddy Bommu - 12 May 2008 06:34 GMT
Hai,
I am looking for bookmarks to be existed even after their text is
auto-inserted. I have the bookmark insert function in this way.

Public Sub BM(NameOfBookmark As String, TextToInsert As Variant)
'this sub handles the insertion text into bookmarks
   Dim Bookmark As String
   Bookmark = NameOfBookmark
   If ActiveDocument.Bookmarks.Exists(NameOfBookmark) Then
       ActiveDocument.Bookmarks(NameOfBookmark).Range.Text = TextToInsert
       
   Else
       Call BMError(NameOfBookmark)
   End If
   
End Sub

Now the problem is that the bookmark (let's say AgreementDay as
NameOfBookmark) is available in the  Microsoft Menu of File-> Insert->
Bookmark options. Once the AgreementDay text is inserted by this call
function, i am not able to see that particular NameOfBookmark again in the
menu of File-> Insert-> Bookmark options. I need the bookmark to exist with
the same name after inserting text as well in the bookmarks list. I tried to
modify the above function in this manner.

Public Sub BM(NameOfBookmark As String, TextToInsert As Variant)
'this sub handles the insertion text into bookmarks
   Dim Bookmark As String
   Bookmark = NameOfBookmark
   If ActiveDocument.Bookmarks.Exists(NameOfBookmark) Then
       ActiveDocument.Bookmarks(NameOfBookmark).Range.Text = TextToInsert
       ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="Bookmark"

   Else
       Call BMError(NameOfBookmark)
   End If
   
End Sub

But, it is not giving the required result. Can anyone help immediately?
Helmut Weber - 12 May 2008 07:56 GMT
Hi,

like that:

Sub MyBookmark(BookmarkName As String, TexttoInsert As String)
Dim rTmp As Range
If ActiveDocument.Bookmarks.Exists(BookmarkName) Then
   Set rTmp = ActiveDocument.Bookmarks(BookmarkName).Range
   rTmp.Text = TexttoInsert
   rTmp.Bookmarks.Add BookmarkName
Else
  MsgBox "No Bookmark: " & BookmarkName
End If
End Sub
' ---------------------------------------------------------------
Sub TestY()
MyBookmark "Test", "xxxxxxxxx"
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.