Splitting words in a text box

  reddwarfcrew 20:46 31 Jan 2006
Locked

Hi,

I have a VBA macro in Word XP that has 3 textboxs

TextBox1 will contain a name, both first and last name

What I want to do is be able to split the value in TextBox1 into 2 so that TextBox2 contains the first name (ie the text up to the space in TextBox1) and TextBox3 contains the lastname (ie the text in TextBox1 after the space).

Any clues on how to achieve this? I assume I will need to use some form of length function and a function to find the space?

Thanks

  reddwarfcrew 21:18 31 Jan 2006

but sorted anyway with (if anyone is interested)


Dim SearchString, SearchChar, MyPos, First, Last

SearchString = TextBox1.Value
SearchChar = " "

MyPos = InStr(1, SearchString, SearchChar, 1)
MyPos = MyPos - 1

First = Mid(SearchString, 1, MyPos)

MyPos = MyPos + 2

Last = Mid(SearchString, MyPos)

TextBox2.Value = First
TextBox3.Value = Last

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

WPA2 hack: How secure is your Wi-Fi?

Add Depth Of Field to a photo using Tilt Shift Blur in Photoshop

iPhone tips & tricks

Les meilleures tablettes 2017