Split a string on the "," character

  • Thread starter Ronald van Zantvoort
  • Start date
R

Ronald van Zantvoort

Hi all,

At some point in the Word 2000 macros I've inherited a string
(RP.strStatPlaats) is called from the database.
This has a format like (for example)

Capelle aan de IJssel, gemeente Capelle aan de Rijn

If there is a ", gemeente" in the string, it needs to bold and underline
everything untill the ,
the rest should be normal text. If not, the entire string should be bold
and underlined.
So here's where I am:

If InStr(RP.strStatPlaats, ", gemeente", vbTextCompare) > 1 Then
Selection.Font.Underline = True
Selection.Font.Bold = True
Selection.TypeText Text:=Left(RP.strStatPlaats, ???)
Selection.Font.Underline = False
Selection.Font.Bold = False
Selection.TypeText Text:=Right(RP.strStatPlaats, ???)
Else
Selection.Font.Underline = True
Selection.Font.Bold = True
Selection.TypeText Text:=RP.strStatPlaats
Selection.Font.Underline = False
Selection.Font.Bold = False
End If

Could someone please fill me in on the ???s?

Thanks loads in advance!

Ronald van Zantvoort
 
J

Jonathan West

Ronald van Zantvoort said:
Hi all,

At some point in the Word 2000 macros I've inherited a string
(RP.strStatPlaats) is called from the database.
This has a format like (for example)

Capelle aan de IJssel, gemeente Capelle aan de Rijn

If there is a ", gemeente" in the string, it needs to bold and underline
everything untill the ,
the rest should be normal text. If not, the entire string should be bold
and underlined.
So here's where I am:

If InStr(RP.strStatPlaats, ", gemeente", vbTextCompare) > 1 Then
Selection.Font.Underline = True
Selection.Font.Bold = True
Selection.TypeText Text:=Left(RP.strStatPlaats, ???)

Should be
Selection.TypeText Text:=Left(RP.strStatPlaats, Instr(RP.strStatPlaats,
","))
Selection.Font.Underline = False
Selection.Font.Bold = False
Selection.TypeText Text:=Right(RP.strStatPlaats, ???)

Should be
Selection.TypeText Text:=Mid(RP.strStatPlaats, Instr(RP.strStatPlaats, ",")
+ 1)
 
J

Jay Freedman

Hi, Ronald,

Try it this way:

Dim nCommaPos As Integer
nCommaPos = InStr(RP.strStatPlaats, ", gemeente", vbTextCompare)
If nCommaPos > 1 Then
Selection.Font.Underline = True
Selection.Font.Bold = True
Selection.TypeText Text:=Left(RP.strStatPlaats, nCommaPos)
Selection.Font.Underline = False
Selection.Font.Bold = False
Selection.TypeText Text:=Right(RP.strStatPlaats, _
Len(RP.strStatPlaats) - nCommaPos)
Else
.... etc
 

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