Word 2000 XPSP2: How to past the content of the clipboard into the FIND-field ?

G

Gunnar

WORD 2000 does NOT allow to drop the content of the clipboard into the
FIND/SEARCH field as it allows to in the REPLACE-field by using the wildcard
"^c".
In the desired MACRO it is needed to drop the recent (changing)
clipboard-content, into the search/find-field (because I want to search
automatically for double-entries in a long list of data (i.e.
telephone-numbers)


Background-information:
The MACRO shall (after copying it from a table into the clipboard) finally
past list-entry #1 into the search/find-field, look through the full list
(table) and stop if there is a positive search-result.
If there is no positive search-result, the MACRO shall proceed with entry#2
the very same way.

Do you have a solution or a work-around?
Gunnar
 
J

Jay Freedman

The solution is not to use Paste in setting up the search. And if you
don't use Paste, then there's also no need to use Copy.

If you select some text and you want the macro to search for it
elsewhere in the document, then you can write the code this way:

Sub LookForSelection()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.ClearFormatting
.Text = Selection.Text ' <== this is the important line
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = False
If .Execute Then
oRg.Select
End If
End With
End Sub

This can be altered to make replacements where the text is found. It
can also be altered to take the search text from successive locations
in a table. I haven't tried to show this because I don't know how your
table is arranged, or where the search is supposed to look, or what
it's supposed to do when it finds something.

Another technique that may work for you is to sort the table first;
then all the duplicates will be placed together. Then you can just
compare each entry with the next entry, and delete one of them if
they're the same.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
G

Gunnar

Hi Jay, thanks for your effort and invested time!

As you suggested correctly, I sorted the table (just one column with a full
phone-number in each row) and double-entries are placed together (row #n,
row #n+1).
Then you can just compare each entry with the next entry, and delete one
of them if they're the same.
That is 100% what the macro should do - no more no less!
Do you think you can provide the usergroup with a macro which does the job?
Thanks anyway
Gunnar
 
G

Greg Maxey

Jay may come along with something cleaner, but this seems to work:

Sub DeleteRowIfDuplicateCell()
Dim oRng1 As Word.Range
Dim oRng2 As Word.Range
Dim i As Long
Dim oRowKill As Boolean
'Sort on the column of interest. In this case a phone number in col 3
Selection.Sort ExcludeHeader:=True, FieldNumber:="Column 3", _
SortFieldType:=wdSortFieldNumeric, SortOrder:=wdSortOrderAscending
'Start with row 2 as I assume you have a header row.
i = 2
Do Until i = Selection.Tables(1).Rows.Count
oRowKill = True
Do While oRowKill
If i = Selection.Tables(1).Rows.Count Then Exit Sub
Set oRng1 = Selection.Tables(1).Cell(i, 3).Range
Set oRng2 = Selection.Tables(1).Cell(i + 1, 3).Range
If oRng1.Text = oRng2.Text Then
Selection.Tables(1).Rows(i + 1).Delete
Else
i = i + 1
oRowKill = False
End If
Loop
Loop
End Sub
 
J

Jay Freedman

Gunnar and Greg --

There's a very similar macro at
http://www.word.mvps.org/FAQs/MacrosVBA/DeleteDupRows.htm. It's just a
little cleaner.

Gunnar, I see that you said your table has only one column. If you use
Greg's code, change all the occurrences of "3" to "1". Also, since the
table is already sorted, you can omit the comment "Sort on the column
of interest..." and the two lines that follow it (although it probably
wouldn't hurt to leave them there).

Greg, since you're incrementing the variable 'i' anyway, you might as
well use a For..Next loop the way Ibby did, instead of the While..Loop
and the boolean variable oRowKill. On the other hand, I don't like
the way Ibby relied on .Text being the default property of the Range
object, and would prefer it to be written explicitly as you did.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
G

Greg Maxey

Thanks Jay.


Jay said:
Gunnar and Greg --

There's a very similar macro at
http://www.word.mvps.org/FAQs/MacrosVBA/DeleteDupRows.htm. It's just a
little cleaner.

Gunnar, I see that you said your table has only one column. If you use
Greg's code, change all the occurrences of "3" to "1". Also, since the
table is already sorted, you can omit the comment "Sort on the column
of interest..." and the two lines that follow it (although it probably
wouldn't hurt to leave them there).

Greg, since you're incrementing the variable 'i' anyway, you might as
well use a For..Next loop the way Ibby did, instead of the While..Loop
and the boolean variable oRowKill. On the other hand, I don't like
the way Ibby relied on .Text being the default property of the Range
object, and would prefer it to be written explicitly as you did.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
G

Gunnar

Hi Jay and Greg (and Ibby),
thanks to all of you - your hints solved my problem to 100% satisfaction !
Great!
Gunnar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top