Adding a search

D

Dan

So, I am trying to create a dictionary with my own temrs
and definitions. I have created a "Definition" document
that contains a 2-column table. First column = Word,
second = Meanings/Definitions.

I have created a code for my "searc" box:

Sub Test()

Dim Message, Title, Default, MyValue
Message = "Search" ' Set prompt.
Title = "Dictionary" ' Set title.
' Display message, title, and default value.

MyValue = InputBox(Message, Title, Default, 100, 100)

End Sub

Now, I am confused with how I can link a search to that
box? Would I use an altered form of this code:

Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

How then could I link it to the box that I created?

THANKS!
 
D

DA

Hi Dan

The MyValue string you're getting from the InputBox is
your search term, so you could apply it to the .text part
of your search in the example you provided.

Problem is though that by doing a standard search you're
going to hit everything, including the search term in
your definitions.

Would be better if you set up a bit of code that only
looks at the first column in your dictionary table and if
it matches, then return the value of your description.

Example:
------
Sub TableSearch()

Dim str2Srch As String
Dim strTerm As String
Dim strDescr As String
Dim tRow As Row

str2Srch = InputBox("Search", "Dictionary")

If str2Srch <> "" Then
With ActiveDocument
For Each tRow In .Tables(1).Rows
strTerm = (.Tables(1).Cell(tRow.Index, 1))
If Left(strTerm, (Len(strTerm) - 2)) = str2Srch Then
strDescr = (.Tables(1).Cell(tRow.Index, 2))
MsgBox "Your Description for " & _
str2Srch & " is: " & strDescr
End If
Next tRow
End With
End If
End Sub
 
G

Guest

Hey!

That is great, it helped a lot.

However, I have another question. How would i get that box
to pop up right when I start Word. Additionly, when i
tried running the macro, the box came up, but i was not
able to search my 2 collumed document.

Thanks for your advice.

-Dan
 
G

Guest

For your startup problem I suggest you make a new button
on your toolbar that links to the search macro. If you
really want the macro to run every time you open the
document, you must place it in the Document_Open() event.

As to my sample, it assumed a document containing a table
(two columns - search items on left, descriptions on
right). If you don't have a table, the macro I gave you
won't work and you'll have to adjust accordingly.

If you get stuck again please try to be as specific as
possible (e.g. specific errors etc.)

Best of luck,
Dennis
 

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