Thread: [Solved] Insert Tabs Between words
View Single Post
Old 11-23-2011, 05:05 PM
lkatz1 lkatz1 is offline Windows XP Office 2010 32bit
Join Date: Nov 2011
Posts: 4
lkatz1 is on a distinguished road
Default Insert Tabs Between words

How can we do a replace by format when we want to find a space between words in Microsoft Word that the first word has a different font then the second?
Example: word1 Word2
we want to put a tab in the space between the 2 words
We have the following macro but only works on first line

Sub ScratchMacro()
Dim oWord As Range
Dim oRgn As Range
For Each oWord In ActiveDocument.Range.Words
If oWord.Font.Name = "Tahoma" Then
If oWord <> vbTab Then
On Error GoTo Err_Handler
If oWord.Words.Last.Next.Font.Name = "Times New Roman" Then
oWord = Replace(oWord, " ", vbTab)
End If
End If
End If
Next oWord
Exit Sub
Resume lbl_Exit
End Sub
Reply With Quote