space macro

S

Sul@MS

I have this one (thanks to someone)

Sub InsertSpaces()
Dim sIn As String, sOut As String
Dim i As Integer

sIn = Selection.Text
For i = 1 To Len(sIn)
sOut = sOut & Mid$(sIn, i, 1) & " "
Next

Selection.Text = sOut
End Sub

the above inserts a space between letters

How to I edit the above to use a dot "." instead of a space ?

example;

this is a test
becomes
t.h.i.s i.s. a. t.e.s.t

tia
 
G

Greg Maxey

You would replace & " "
witn & "."

You could also adapt the code to allow user to select the character:

Sub InsertCharacter()
Dim sIn As String
Dim sOut As String
Dim i As Long
Dim sChar As String
sChar = InputBox("Enter the character to insert", "Character", ".")
sIn = Selection.Text
For i = 1 To Len(sIn)
sOut = sOut & Mid$(sIn, i, 1) & sChar
Next
Selection.Text = sOut
End Sub
 
W

Win7

thanks for the tip

Greg Maxey said:
You would replace & " "
witn & "."

You could also adapt the code to allow user to select the character:

Sub InsertCharacter()
Dim sIn As String
Dim sOut As String
Dim i As Long
Dim sChar As String
sChar = InputBox("Enter the character to insert", "Character", ".")
sIn = Selection.Text
For i = 1 To Len(sIn)
sOut = sOut & Mid$(sIn, i, 1) & sChar
Next
Selection.Text = sOut
End Sub
 

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