Writing Macro for word in VBA..

Hi All,

Please help me for writing macro in VBA for removing leading as well as trailing spaces of relational as well as arithmetic operators.
I tried using "Trim" as well as "$Trim" functuion from VB...but it does not remove all the leading and trailing spaces.Please see copy and paste of the code.Guide me!!
Sub Operator_Spaces()
Set myRange = ActiveDocument.Content
Dim Operators(1 To 21) As String
Dim i, j, k, Table_Cnt As Long
Dim Find_Match As String
Operators(1) = " < "
Operators(2) = " > "
Operators(3) = " <= "
Operators(4) = " >= "
Operators(5) = " <"
Operators(6) = " >"
Operators(7) = " <="
Operators(8) = " >="
Operators(9) = "< "
Operators(10) = "> "
Operators(11) = "<= "
Operators(12) = ">= "
Operators(13) = " + "
Operators(14) = " - "
Operators(15) = " / "
Operators(16) = " +"
Operators(17) = " -"
Operators(18) = " /"
Operators(19) = "+ "
Operators(20) = "- "
Operators(21) = "/ "

myRange.WholeStory
For i = 1 To 21
With myRange.Find
.Text = Operators(i)
Find_Match = Operators(i)
.Replacement.Text = Trim(Find_Match)
.Replacement.Font.Color = wdColorAutomatic
.Replacement.Font.Subscript = False
.Execute Replace:=wdReplaceAll
End With

For Each Table In ActiveDocument.Tables
With Table
With myRange.Find
.Text = Operators(i)
Find_Match = Operators(i)
.Replacement.Text = Strings.$Trim(Find_Match)
.Replacement.Font.Color = wdColorAutomatic
.Replacement.Font.Subscript = False
.Execute Replace:=wdReplaceAll
End With
End With
Next Table
Next i

Aso please suggest me for removing the spaces before or after that of special symbols..like £,³ & ¹.

Replies

You are reading an archived discussion.

Related Posts

hi i need your help on the project of mechanical .please help me and suggest some new opics to me which is economical too.
CEans! CrazyEngineers is giving away free passes to CEans who want to attend :- NVIDIA's NVISION 2008 [ August 25 - 27, San Jose, CA ] About NVISION 2008 in...
Discuss the announcement -> https://www.crazyengineers.com/forum...-nvision-2008-we-giving-away-free-passes.html In this thread! 😁
Note: The protagonist (our own CEan) in following case study is actually going through the hell, as described below. By posting this case study for discussion, we will try to...
Hello this is Anurag new to CE.......nice to meet all u ppl.....😁 Name: Anurag *Engineering Trade: Computer Science Location: Pune/India *Occupation:Working (AMDOCS@Pune) Work Experience: Fresher *Hobbies & Interests: Reading Books,watching...