Мне нужен макрос для MS Word, который проверит документ и применит правила к символам "/": "и". "он должен добавить "Пробел" до и после "/". Он должен добавить s "Пробел", "Пробел" после ":" и "."только если нет "пробелов", как описано.
Я использовал (Selection.MoveRight Unit: = wdCharacter, Count: = - 1, Extend: = wdMove), чтобы переместить курсор в место, где должны выполняться проверки и изменения.Это работает, но невероятно медленно
Слушайте мой код:
Sub FIX_Space1 ()
Dim Title As String
Dim CharCount As Integer
Dim Message As String
Dim Char1 As String
Dim NextChar As String
Dim NextChar1 As String
Dim x As Long
ActiveDocument.Range(0, 0).Select
Selection.WholeStory
Title = "CharCount"
CharCount = Len(Selection)
For x = 0 To CharCount
ActiveDocument.Range(0, 0).Select
Selection.MoveRight Unit:=wdCharacter, Count:=x, Extend:=wdMove
NextChar = Selection
'## check for "/"
If NextChar = "/" Then
'Check for space one back
Selection.MoveRight Unit:=wdCharacter, Count:=-1, Extend:=wdMove
NextChar1 = Selection
If NextChar1 = " " Then
Else
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
Selection.Text = " "
End If
'Check for space one forward
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdMove
NextChar1 = Selection
If NextChar1 = " " Then
Else
Selection.Text = " "
End If
End If
'## check for ":"
If NextChar = ":" Then
'Check for : one forward
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
NextChar1 = Selection
If NextChar1 = " " Then
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
NextChar1 = Selection
If NextChar1 = " " Then
Else
Selection.Text = " "
End If
Else
Selection.Text = " "
End If
End If
'## check for "."
If NextChar = "." Then
'Check for : one forward
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
NextChar1 = Selection
If NextChar1 = " " Then
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
NextChar1 = Selection
If NextChar1 = " " Then
Else
Selection.Text = " "
End If
Else
Selection.Text = " "
End If
End If
Next x
End Sub