Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-05-2014, 06:52 AM
TechEd TechEd is offline Why is this Find string not working Windows XP Why is this Find string not working Office 2010 32bit
Novice
Why is this Find string not working
 
Join Date: May 2011
Posts: 16
TechEd is on a distinguished road
Default 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 ????
Reply With Quote
  #2  
Old 07-05-2014, 08:27 AM
gmaxey gmaxey is offline Why is this Find string not working Windows 7 32bit Why is this Find string not working Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Why don't you use <[A-Z]{3,4}> in your code? What is strAcronymn?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 07-05-2014, 05:02 PM
TechEd TechEd is offline Why is this Find string not working Windows 7 64bit Why is this Find string not working Office 2013
Novice
Why is this Find string not working
 
Join Date: May 2011
Posts: 16
TechEd is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 07-05-2014, 06:24 PM
gmaxey gmaxey is offline Why is this Find string not working Windows 7 32bit Why is this Find string not working Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 07-05-2014, 07:55 PM
TechEd TechEd is offline Why is this Find string not working Windows 7 64bit Why is this Find string not working Office 2013
Novice
Why is this Find string not working
 
Join Date: May 2011
Posts: 16
TechEd is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 07-05-2014, 08:12 PM
gmaxey gmaxey is offline Why is this Find string not working Windows 7 32bit Why is this Find string not working Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is this Find string not working Find and Replace is not working Brigitte Word 7 06-15-2021 05:10 PM
Why is this Find string not working 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
Why is this Find string not working string concat stopped working? AlexanderJohnWilley Excel 6 09-27-2013 08:39 PM
Why is this Find string not working Find and replace a string of text errtu Word 1 01-31-2013 02:09 PM
Why is this Find string not working Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:19 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft