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.

Help with Prompts = Code attached Simple if statement?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Casey Mac - 20 Oct 2005 03:25 GMT
hello,

What im wanting to try is for this code to cycle through the document and
once you have imputted your criteria:

sFnd = Enter the word you wish to replace with a hyperlink
sHpl = Enter File Name
sDsp = Enter the HyperLink display name

it will prompt you once it finds the word you wish to replace.  At that
point you can choose either yes (to replace it) or no to ignore it.

Im thinking this must be a simple if statement but for the life of me i cant
find where it should go. I have a partial piece "MsgBox "Replace selection",
vbYesNo, "Testing" but cant figure out the rest.

Please help. i would like to try and sleep tonight.

Thanks

cm

Sub FindAndReplaceWithHypertext()
Dim rDoc As Range     ' range replace
Dim sFnd As String    ' string to be found
Dim sHpl As String    ' hyperlink
Dim sDsp As String    ' hyperlink display

sFnd = InputBox("Enter the word you wish to replace with a hyperlink:")
sHpl = InputBox("Enter File Name:")
sDsp = InputBox("Enter the HyperLink display name")

Set rDoc = ActiveDocument.Range
ResetSearch
With rDoc.Find
  .Text = sFnd
  .Wrap = wdFindStop

MsgBox "Replace selection", vbYesNo, "Testing"
   Do While .Execute
      ActiveDocument.Hyperlinks.Add _
      rDoc, sHpl, TextToDisplay:=sDsp
      rDoc.End = rDoc.End + Len(sDsp)
      rDoc.Collapse wdCollapseEnd
     Loop
End With

End Sub
David Kavanagh - 20 Oct 2005 17:31 GMT
I think the following is probably what you need:

Sub FindAndReplaceWithHypertext()
Dim rDoc As Range     ' range replace
Dim sFnd As String    ' string to be found
Dim sHpl As String    ' hyperlink
Dim sDsp As String    ' hyperlink display

sFnd = InputBox("Enter the word you wish to replace with a hyperlink:")
sHpl = InputBox("Enter File Name:")
sDsp = InputBox("Enter the HyperLink display name")

Set rDoc = ActiveDocument.Range
ResetSearch
With rDoc.Find
  .Text = sFnd
  .Wrap = wdFindStop

   Do While .Execute
       rDoc.Select
       If MsgBox("Replace selection?", vbYesNo, "Testing") = vbYes Then
           ActiveDocument.Hyperlinks.Add _
           rDoc, sHpl, TextToDisplay:=sDsp
           rDoc.End = rDoc.End + Len(sDsp)   '  I'm not convinced you need
this line
           rDoc.Collapse wdCollapseEnd
       End If
     Loop
End With

Regards,
David.

> hello,
>
[quoted text clipped - 44 lines]
>
> End Sub

Rate this thread:






 
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.