Модуль для MS Word Удаление лишних Enter, Удаление лишних пробелов из выделенного текста (оставляет только один пробел), Вставка неформатированного текста из буфера.
Исходник dhMyNormal.bas, можно сохранить как модуль в шаблон Normal.dot будет работать для всех документов. Запуск через "Выполнить макрос"
Attribute VB_Name = "dhMyNormal"
Public Sub Удаление_лишних_Enter()
'Проверка происходит построчно, результат _
записывается в переменную
Dim kol%, i%
Dim strText1 As String
Dim strChE_1 As String
Dim strText2 As String
Dim strChH_2 As String
Dim strOut As String
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
kol% = ActiveDocument.BuiltInDocumentProperties("Number of lines")
For i% = 1 To kol%
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
strText1 = Selection
strChE_1 = Mid(Selection, Len(RTrim(Selection)), 1)
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
strText2 = Selection
strChH_2 = Mid(LTrim(Selection), 1, 1)
If strChE_1 = Chr(10) Or strChE_1 = Chr(13) Then
If Asc(strChH_2) >= 224 Or strChH_2 = Chr(13) _
Or strChH_2 = Chr(10) Then
strOut = strOut & Mid(strText1, 1, Len(strText1) - 1) & " "
Else
strOut = strOut & strText1
End If
Else
strOut = strOut & strText1
End If
Next
strOut = dhTrimAll(strOut)
Selection.WholeStory
Selection = strOut
End Sub
Public Function dhTrimAll(ByVal strText As String) As String
'Удаление лишних пробелов из выделенного
'текста (оставляет только один пробел)
Dim strTemp As String
Dim strOut As String
Dim intI As Integer
Dim strCh As String * 1
strTemp = Trim(strText)
For intI = 1 To Len(strTemp)
strCh = Mid$(strTemp, intI, 1)
If Not (strCh = " " And Right(strOut, 1) = " ") Then
strOut = strOut & strCh
End If
Next intI
dhTrimAll = strOut
End Function
Public Sub Удаление_лишних_пробелов()
Dim strVidelen As String
Selection.WholeStory
strVidelen = Selection
Selection = dhTrimAll(strVidelen)
End Sub
Public Sub Insert_Not_Format()
'
' Вставка неформатированного текста из буфера
'
Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
wdInLine, DisplayAsIcon:=False
End Sub
Public Sub Num_Pages()
'
' Вставка номеров страниц
' Формат: вверху, по центру, включая первую
'
Selection.Sections(1).Headers(1).PageNumbers.Add PageNumberAlignment:= _
wdAlignPageNumberCenter, FirstPage:=True
End Sub
Sub select_formating()
' Форматирование выделенного целиком слова в полужирный текст
Dim strText As String
strTxt = Selection
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Bold = True
With Selection.Find
.Text = txt
.Replacement.Text = txt
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub