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 / October 2005

Tip: Looking for answers? Try searching our database.

create a bookmark

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shawn G. - 05 Oct 2005 14:26 GMT
What is the VBA to find text and create a bookmark?
I need to search the doc for a prase, <insert bookmark>
then turn that into a bookmark named bkmrkName

Any ideas?

Thanks!
Helmut Weber - 05 Oct 2005 14:33 GMT
Hi Shawn,

as easy as that, once you know.

Sub test0009()
Dim rDoc As Range
Set rDoc = ActiveDocument.Range
resetsearch
With rDoc.Find
  .Text = "Steve"
  If .Execute Then
     rDoc.Bookmarks.Add Name:="Name", Range:=rDoc
  End If
End With
resetsearch
End Sub

' ---
Public Sub ResetSearch()
With Selection.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = ""
  .Replacement.Text = ""
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Execute
End With
End Sub

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Shawn G. - 05 Oct 2005 14:54 GMT
I was hopeing you were online! It works great Thanks!!!
An idea how to make this work from excel?

> Hi Shawn,
>
[quoted text clipped - 31 lines]
> End With
> End Sub
Helmut Weber - 05 Oct 2005 23:29 GMT
Hi Shawn,

like this:

Sub Exceltest0009()
' reference to word is set
' in tools references
' the word document is already open
Dim oWrd As Word.Application
Set oWrd = GetObject(, "Word.Application")
Dim oDoc As Word.Document
Set oDoc = oWrd.ActiveDocument
Dim rTmp As Word.Range
Set rTmp = oDoc.Range
With rTmp.Find
  .Text = "Krypton"
  If .Execute Then
     rTmp.Bookmarks.Add Name:="Krypton", _
     Range:=rTmp
  End If
End With
End Sub

see:
http://word.mvps.org/faqs/interdev/EarlyvsLateBinding.htm
http://word.mvps.org/faqs/interdev/ControlWordFromXL.htm

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Shawn G. - 06 Oct 2005 14:36 GMT
Helmut,
You are awesome! I spent all day yesterday trying to make this work and even
asked several times on the Excel programming Group And you solved the
problem!!!
Thank You Very Much!!!!!

> Hi Shawn,
>
[quoted text clipped - 22 lines]
> http://word.mvps.org/faqs/interdev/EarlyvsLateBinding.htm
> http://word.mvps.org/faqs/interdev/ControlWordFromXL.htm
 
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.