PDA

View Full Version : Solved: Finding a String



Drifter518
11-25-2008, 11:59 AM
Hey Everyone,

I am trying to do a simple find but using a String as the object I'm looking for. The code below is wrong but might give you an idea of what I'm looking for

Dim funcabr As String
Dim TableName As String
Dim FullTableName As String
funcabr = "BM_"
For i = 1 To 1000
TableName = funcabr + Str$(i)
FullTableName = "Table " + TableName
Selection.Find.ClearFormatting
With Selection.Find
.Text = TableName
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
' End With
Selection.Find.Execute

fumei
11-25-2008, 01:21 PM
Try following up, and use some things from your other thread. My suggestions there are applicable here.

fumei
11-25-2008, 01:30 PM
Could you please use the VBA code tags? Thanks.


For i = 1 to 1000

You have 1000 tables??

If these "BM_x" are Captions, then why not search for the Caption style?

I do not see why you make all those variables.

For i = 1 To 1000
Selection.Find.ClearFormatting
With Selection.Find
.Text = "BM_" & i

I fail to see why you are using funcabr, TableName, or FullTableName...especially as you do not seen to actually use FullTableName.

Drifter518
11-25-2008, 01:49 PM
Hi fumei,

Sorry for the lack of VBA code tags, I'm still getting used the to forum, I wondered how you guys did that, now I see. :)

I don't have a 1000 tables but what I do have is some people use numbers up in the 100's for their tables, if I could get them to just use lower numbers I would. :)

These actually aren't captions yet, what I do is I key off of the BM_x table name and then place a caption at the end of the the paragraph where they're found.

This is just part of the code, it's a few hundred lines and didn't think I should post it all, especially where the only thing I'm trying to ask about is the searching on the String.

I tried to use the .execute(FindText :=TableName .....) command that you gave me in my last post but it gives me a false value meaning it doesn't find the Table name.

Should I be using something different besides "FindText" is there like a "FindString" option??

Thanks for your help

Drifter518
11-25-2008, 02:16 PM
Figured it out, Thanks Fumei turned out the problem was my assigning the TableName variable.

Wrong:

TableName = funcabr + Str$(i)


Right

TableName = funcabr & i


Thanks again

fumei
11-26-2008, 10:54 AM
You are welcome.

I would still recommend using only the number of variables you actually need. And you do not need - at least as far as I can see - funcabr, TableName, or FullTableName.

"Should I be using something different besides "FindText" is there like a "FindString" option??"

FindText is a string value. Generally speaking "text" IS "string". So anywhere you see "text" as a parameter, it means a string.

.Find.Text = a string value

.TypeText Text:= a string value

.Range.Text = a string value