I need a Word Macro to convert selection text from this:
This is a =selection in a word =document.
To this:
This is a s________ in a word d_______.
Can anyone help me out?
I've tried
Sub conv_1()
Dim Sentence As String
Dim i As Integer
Sentence = Selection.Text
For i = 1 To Len(Sentence)
If Mid(Sentence, i, 1) Like "[a-zA-Z]" Then
Mid(Sentence, i, 1) = "_"
End If
Next i
Selection.Text = Sentence
End Sub
but it converts all the selected words to Dash-Dash-Dash.
I've also tried
Sub conv_2()
'Declare variables
Dim intCount As Integer
Dim intLength As Integer
Dim strInput As String
Dim strOutput As String
Dim strTemp As String
'Get the selected text
strInput = Selection
'If nothing is selected, exit
If strInput = "" Then
Exit Sub
End If
'Split the string into an array
Dim arrWords
arrWords = Split(strInput)
'Loop through each word in the array
For intCount = LBound(arrWords) To UBound(arrWords)
'Get the length of the word
intLength = Len(arrWords(intCount))
'If the word is longer than 1 character, convert the word
If intLength > 1 Then
strTemp = arrWords(intCount)
strOutput = strOutput & Left(strTemp, 1) & String(intLength - 2, "_") & _
Right(strTemp, 1) & " "
Else
'If the word is 1 character, add it to the output string
strOutput = strOutput & arrWords(intCount) & " "
End If
Next
'Trim the trailing space
strOutput = Trim(strOutput)
'Replace the original selection with the converted text
Selection.TypeText Text:=strOutput
End Sub
but it converts all words into A-Dash-A.
I don't know how to make it so that only the words that have an equal sign next to them get turned into A-Dash-Dash. I would appreciate any help on this!