How to find any of a set of characters in a string

MS WORD

    Next

  • 1. Can I create a "book"?
    In EXCEL I can assemble a number of files in one BOOK (thats is the word in the Swedish version). Unfortunately that applies to EXCEL-files only. A project almost always consists of .doc-files also. It is a pity that they cannot be saved in the EXCEL book. Is there a way to create a book or similar in WORD containing ..doc-files?
  • 2. How to insert mergefield inside a includepicture field using VB
    Hi, currently, I use the following code: Dim fldCode as String WordMergeField = WordMergeFields.Add(WordSelection.Range, type) fldCode = WordMergeField.Code.Text WordMergeField.Delete() WordInline.AddPicture("C:\proj\hrosen\JPT0803\Signature\" & fldCode & ".bmp", True, False, WordSelection.Range) The problem is Code.text removes the brackets around the wordMergeField. the merge field I'm using actually provides the name of each image. Basically I want the Document to show up something like, {INCLUDEPICTURE "C:\\proj\\hrosen\\JPT0803\\Signature\\{MergeField LIST}.bmp" \d } instead, I'm getting {INCLUDEPICTURE "C:\\proj\\hrosen\\JPT0803\\Signature\\MergeField LIST.bmp" \d } with this code. What can I do to change this? Thanks
  • 3. Check in code to see if application is open
    Can anyone tell me the easiest way to check if Word is open on the computer? I have automation code (in Excel and Access) that creates Word letters and faxes automatically, but I don't want the code to start another copy of Word if the application is already open. Thanks for any tip! Kristian
  • 4. Knowing when an object can be ungrouped programmatically
    Hi, I've a macro that ungroups embedded objects, grouped objects and pictures. When you try to ungroup an object manually, if further ungrouping is not possible, then the ungroup option is grayed out. Is there a way to find out programmatically if the object cannot be ungrouped? Thanks, Purvi
  • 5. Macro to add drop down values
    This is a multi-part message in MIME format. I want to be able to add items dynamically to a drop down depending on what item was selected in the previous one I need full code David Legg <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1264" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2>I want to be able to add items dynamically to a drop down depending on what item was selected in the previous one</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>I need full code</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>David Legg</FONT></DIV></BODY></HTML>

How to find any of a set of characters in a string

Postby UGhpbGlwIEJyb3du » Mon, 05 Feb 2007 04:26:00 GMT

Hello,

How do I determine if one or more of a set of characters occurs in a given 
string?

For example, I need to determine if d, D, or r occurs in the current .range 
object.

I was hoping for something like:

InStr(1, .range, "[aDr]") but that doesn't work.

Any help would be appreciated!

RE: How to find any of a set of characters in a string

Postby UGhpbGlwIEJyb3du » Mon, 05 Feb 2007 05:56:16 GMT

I solved my problem using the following

If .moveuntil(CSet:="dDr", Count:=5) = 0 Then ...

The range object is not changed if none of the characters specified in CSet 
are found. MoveUntil returns a zero is the range object is not changed. In 
this way, I have verified that none of the specified characters exists in the 
range.





Re: How to find any of a set of characters in a string

Postby Helmut Weber » Mon, 05 Feb 2007 06:02:27 GMT

Hi Philip,

like this:

Sub Test900()
MsgBox IsInRange(selection.Range, "dDr")
End Sub
' -------------------------------
Public Function IsInRange _
(rngTmp As Range, strTmp As String) As Boolean
IsInRange = False
With rngTmp.Find
   .Text = "[" & strTmp & "]"
   .MatchWildcards = True
   If .Execute Then
      IsInRange = True
   End If
End With
End Function


-- 
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

RE: How to find any of a set of characters in a string

Postby bXV5Qk4 » Mon, 05 Feb 2007 06:11:07 GMT

If you have some text selected, then the following code will test if the 
selection is any of the following: lower case a through z; upper case a 
through z; or digits 0 through 9. 

If Selection Like "[a-z/A-Z/0-9]" Then...

Using this as a model, experiment replacing what I have between the 
brackets. I believe the name for it in VB is "normal expression" if you want 
to do more research.

I work with Selection more than I do with Range, but I believe that if you 
want to test in a certain range, you would write .Range then .whatever after 
that.

What I've written is valid but maybe someone else with more exerience in 
these other areas can fill in the blanks.

-- 
Bryan






Similar Threads:

1.Find number of characters in string

2.Finding strings of the character ^

Try ^^{1,} (see Word 2002 Help topic "Codes for items you want to find and
replace").

"Greg" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
> I am trying to find strings of 1 or more of the character ^.  in the
> Find what field.  Find ^ will find single instances but I just noticed
> that Word generates an error if you use ^{1,}.  Does anyone know how to
> find strings of 1 or more of this character?
>


3.Find String, Copy/Paste Next 255+ Characters to New .doc

Does anyone know of a way to search for a certain string, such as 
dditionaland then copy/paste this into a new document, along with the 
following 255 characters?  Is 255 the limit?  I found the code below on this 
DG: 

Sub RTM4()
Dim oDoc As Document
Dim oSrcRg As Range, oDestRg As Range

Set oSrcRg = ActiveDocument.Range
Set oDoc = Documents.Add
Set oDestRg = oDoc.Range
oDestRg.Collapse wdCollapseEnd

With oSrcRg.Find
.ClearFormatting
.Text = "Additional ?{255}"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

Do While .Execute
oDestRg.FormattedText = oSrcRg.FormattedText
oDestRg.Collapse wdCollapseEnd
oDestRg.InsertParagraph
oDestRg.Collapse wdCollapseEnd
Loop
End With

Set oDestRg = oDoc.Range
oDestRg.ConvertToTable Separator:=wdSeparateByTabs, _
NumColumns:=3, NumRows:=100, _
AutoFitBehavior:=wdAutoFitFixed
With oDoc.Tables(1)
.Style = "Table Grid"
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With

oDoc.Activate

Set oSrcRg = Nothing
Set oDestRg = Nothing
Set oDoc = Nothing
End Sub


It works great.  Sometimes the string, such as dditionalis in a table, 
and the code seems to struggle with the tables sometimes.  For instance, if I 
have the word dditionalin one table, I'd like to find 255 characters, or 
more, up to 500 characters, in an adjacent table, just to the right on this 
table.  Any suggestions?

Regards,
Ryan

-- 
RyGuy

4.Finding Character in String

I want to return the name of the drawing file (DWG) from the end of a string.
The string will be of varying lengths... as well as the drawing file name
itself.

I could do it the long way by getting the length of the string, and
subtracting one character at a time until I hit the  '\' character... then
I'll know how much to subtract to get my file name.

An example of the string is:
"P:\Projects\2004\10-02-230 (ProjectName\600 Drawings\E101.dwg"

But is there an easier (and faster) way to search for the last '\' character
in my string?  (keep in mind that the number of '\' in each string will also
vary).

Thanks in advance!

Regards,

Bruce

5.Finding a Character in a String Using VBA

Hi,

I am trying to return an integer for the number of characters from the left 
of a string that the character "/" is located.

I need to do this using VBA as I am trying to trim the value of a cell.

Can anyone help?

BVass

6. Finding a particular character in a string using VBA

7. Using Excel VBA - Finding Characters in Strings

8. Function to find certain character in String



Return to MS WORD

 

Who is online

Users browsing this forum: No registered users and 58 guest