Find & Replace using input box 
Author Message
 Find & Replace using input box

I have a macro that I recorded that finds and replaces text. I would like to
be able to customize this though, so that the "FIND" text would be able to
be put in an input box and then have the program find whatever is input and
replace it with a certain value.
For example:
What would you like to delete?
"Section A" (in the input box)
Then replace "Section A" with nothing.

I hope this makes sense. I hope I'm in the right place--I'm definately a
beginner!

Thanks,
Kelly



Tue, 16 Aug 2005 02:39:49 GMT  
 Find & Replace using input box
Hi Kelly,

I think you can use something like the following:

Dim sFindText As String

sFindText = InputBox(Prompt:="Enter your search word(s).")

With Selection
    .HomeKey Unit:=wdStory
    With .Find
        .ClearFormatting
        .Text = sFindText
        If Not .Execute Then
            MsgBox "Word could not find """ & sFindText & """."
        End If
    End With
End With

HTH

Quote:
> I have a macro that I recorded that finds and replaces text. I would like
to
> be able to customize this though, so that the "FIND" text would be able to
> be put in an input box and then have the program find whatever is input
and
> replace it with a certain value.
> For example:
> What would you like to delete?
> "Section A" (in the input box)
> Then replace "Section A" with nothing.

> I hope this makes sense. I hope I'm in the right place--I'm definately a
> beginner!

> Thanks,
> Kelly



Tue, 16 Aug 2005 02:47:45 GMT  
 Find & Replace using input box
Hello Kelly

How about using Word's Find and Replace dialog box in your macro?  This will
allow you to be much more specific about what you are finding and replacing.
Place the following code in the appropriate part of your macro:-

Dialogs(wdDialogEditReplace).Show

With Dialogs(wdDialogEditReplace)
            .ReplaceAll = 1
            .Execute
End With

If you are processing a batch of files you will find this article very
useful http://www.mvps.org/word/FAQs/MacrosVBA/BatchFR.htm

Angela


Quote:
> I have a macro that I recorded that finds and replaces text. I would like
to
> be able to customize this though, so that the "FIND" text would be able to
> be put in an input box and then have the program find whatever is input
and
> replace it with a certain value.
> For example:
> What would you like to delete?
> "Section A" (in the input box)
> Then replace "Section A" with nothing.

> I hope this makes sense. I hope I'm in the right place--I'm definately a
> beginner!

> Thanks,
> Kelly



Tue, 16 Aug 2005 03:58:18 GMT  
 Find & Replace using input box
Thanks so much!!!  That worked perfectly!
May I ask what the lower case s before FindText does?


Tue, 16 Aug 2005 04:42:29 GMT  
 Find & Replace using input box
Hi Kelly,

Just my way of saying that I have dimensioned the variable as a string,
which helps if I have to debug the routine.

HTH


Quote:
> Thanks so much!!!  That worked perfectly!
> May I ask what the lower case s before FindText does?



Tue, 16 Aug 2005 04:51:10 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Using Find and Replace to find Section Breaks

2. Writing Find and Replace Dialogs using RichTextBox.Find Function

3. ?How Can Option Buttons replace Input Box?

4. Randomly replacing a cell with an input box

5. Permission denied when using Input boxes and message boxes

6. Find & Replace Problem - ACC97

7. Find& replace one by one

8. FIND & REPLACE

9. Multiple find & replace

10. Find&replace-code

11. find & Replace with wild cards and patterns

12. find/replace on headers&footers

 

 
Powered by phpBB® Forum Software