How to get some word and characters?

A

avkokin

Hello. There is TextBox1 (on UserForm) which composed of three-words
(russian family name). First word is the surname (e.g. Nabokov),
second word - patronymic (e.g. Vladimirovich) and third word - first
name (e.g. Vladimir). Thereby we have full russian family name -
Vladimir Vladimirovich Nabokov.
I need get from it two results of the following types:
1: Nabokov V.V. (surname with initials)
2: Vladimir Vladimirovich (without surname)
How to do this?
Thank you!
 
G

Graham Mayor

The following will work:

Dim sText As String
Dim sSurname As String
Dim sForename As String
Dim sPatronymic As String
Dim sInit1 As String
Dim sInit2 As String

sText = ActiveDocument.FormFields("Text1").Result
sSurname = Mid(sText, InStrRev(sText, " ") + 1, Len(sText) - InStrRev(sText,
" ") + 1)
sPatronymic = Mid(sText, InStr(1, sText, " ") + 1, InStrRev(sText, " ") -
InStr(1, sText, " "))
sForename = Mid(sText, 1, Len(sText) - (Len(sText) - InStr(1, sText, " ")))
sInit1 = Left(sText, 1) 'First initial
sInit2 = Left(sPatronymic, 1) 'Second Initial

MsgBox sSurname & Chr(32) & sInit1 & Chr(46) & Chr(32) & sInit2 & Chr(46) _
& vbCr & sForename & sPatronymic

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
H

Helmut Weber

Hi Anton,

like that:

Sub Test567()
Dim sText As String
Dim sResult1 As String
Dim sResult2 As String
Dim sArray() As String
sText = "Nabokov Vladimirovich Vladimir"
' or the text from your textbox
sArray = Split(sText)
sResult1 = sArray(0) & " "
sResult1 = sResult1 & Left(sArray(1), 1) & ". "
sResult1 = sResult1 & Left(sArray(2), 1) & "."
sResult2 = sArray(2) & " "
sResult2 = sResult2 & sArray(1)
MsgBox sResult1
MsgBox sResult2
End Sub


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
A

avkokin

Hi Anton,

like that:

Sub Test567()
Dim sText As String
Dim sResult1 As String
Dim sResult2 As String
Dim sArray() As String
sText = "Nabokov Vladimirovich Vladimir"
' or the text from your textbox
sArray = Split(sText)
sResult1 = sArray(0) & " "
sResult1 = sResult1 & Left(sArray(1), 1) & ". "
sResult1 = sResult1 & Left(sArray(2), 1) & "."
sResult2 = sArray(2) & " "
sResult2 = sResult2 & sArray(1)
MsgBox sResult1
MsgBox sResult2
End Sub

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Thank you very much!
Der Vielen Dank f¨¹r die Hilfe!
P.S. I was a little wrong: first name is a Forename (e.g. Vladimir),
second name is a Patronimic (e.g. Vladimirovich), and third name is a
Last name or Surname (e.g. Nabokov). Though yours codes is very helped
for me.
 

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