#1
|
|||
|
|||
Why is this Find string not working
I am using the following string to find acronyms in reports.
.Text = "<[A-Z]{3" & strAcronym & "}>" This line works fine and finds all uppercase groups of three or more letters, e.g. ABC, HELP, UNIFORM. But, when I try the following code: .Text = "<[A-Z]{3,4" & strAcronym & "}>" which should find all instances of uppercase groups, but limited to three or four letters, it doesn't work and I get an error message. Something I tried: If i use the Find and Replace dialog box and enter <[A-Z]{3,4}> It works Any ideas ???? |
#2
|
|||
|
|||
Why don't you use <[A-Z]{3,4}> in your code? What is strAcronymn?
|
#3
|
|||
|
|||
I want the Find string to search through a report, capture all the acronyms, and put them in a table at the beginning of the report. To do this the string is in a loop. Each time the code loops through the report and finds an instance of an uppercase group of three or more letters it place it in strAcronym (a string variable) so it can be added to the table.
As i said using just "<[A-Z]{3" & strAcronym & "}>" works fine except there is no upper limit on the length of the groups of letters it finds - and I just wondered why I can't simply add the 4 as that upper limit. |
#4
|
|||
|
|||
It doesn't error here, but then I don't have all of your code and putting strAcronym in the find what field seems like nonsense to me.
Try: Code:
Sub ScratchMacrop() Dim oCol As New Collection Dim lngIndex As Long 'A basic Word macro coded by Greg Maxey Dim oRng As Word.Range lngIndex = 0 Set oRng = ActiveDocument.Range With oRng.Find .Text = "<[A-Z]{3,4}>" .MatchWildcards = True While .Execute On Error Resume Next oCol.Add oRng.Text, oRng.Text On Error GoTo 0 oRng.Collapse wdCollapseEnd Wend End With For lngIndex = 1 To oCol.Count MsgBox oCol(lngIndex) Next lngIndex End Sub |
#5
|
|||
|
|||
Greg, Thanks for the reply, you are absolutely correct - and here I am eating humble pie- I am an idiot and did not fully understand the code I was working on. The strvariable should not have been there and that is what was causing the problem. That will teach me to read the whole procedure before I jump to conclusions... ...sorry to have wasted everybodys time with this one.
|
#6
|
|||
|
|||
TechEd,
Ha! You are not the only one who sometimes tastes humble pie ;-). Glad to have helped you through a through a tough spot. Good luck. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Find and Replace is not working | Brigitte | Word | 7 | 06-15-2021 05:10 PM |
Way to search for a string in text file, pull out everything until another string? | omahadivision | Excel Programming | 12 | 11-23-2013 12:10 PM |
string concat stopped working? | AlexanderJohnWilley | Excel | 6 | 09-27-2013 08:39 PM |
Find and replace a string of text | errtu | Word | 1 | 01-31-2013 02:09 PM |
Bad view when using Find and Find & Replace - Word places found string on top line | paulkaye | Word | 4 | 12-06-2011 11:05 PM |