space macro

  • Thread starter Thread starter Sul@MS
  • Start date Start date
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
 
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
 
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
 
Back
Top