UPD:
Изменения!!!
________________
Option Explicit
Sub Alltext_to_curve_Svoe()
Dim pageIndex As Long
Dim j As Long
Dim textList As Collection
Dim s As Shape
Dim foundCount As Long
Dim convertedCount As Long
Dim weldCount As Long
Dim failedCount As Long
Dim pageFound As Long
Dim pageConverted As Long
Dim pageWeld As Long
Dim pageFailed As Long
Dim report As String
Dim errorText As String
Dim commandStarted As Boolean
On Error GoTo ErrorHandler
ActiveDocument.BeginCommandGroup "All Text to Curves + Weld"
commandStarted = True
' ==========================================
' 1. Обрабатываем обычные страницы по очереди
' ==========================================
For pageIndex = 1 To ActiveDocument.Pages.Count
Set textList = New Collection
pageFound = 0
pageConverted = 0
pageWeld = 0
pageFailed = 0
' Собираем текст только текущей страницы
CollectPageText ActiveDocument.Pages(pageIndex).shapes, textList
pageFound = textList.Count
foundCount = foundCount + pageFound
' Обрабатываем найденный текст в обратном порядке
For j = textList.Count To 1 Step -1
Set s = textList(j)
If ConvertAndWeldOne( _
s, pageWeld) Then
pageConverted = pageConverted + 1
Else
pageFailed = pageFailed + 1
End If
Next j
convertedCount = convertedCount + pageConverted
weldCount = weldCount + pageWeld
failedCount = failedCount + pageFailed
report = report & _
"Страница " & pageIndex & vbCrLf & _
" Найдено текстовых объектов: " & pageFound & vbCrLf & _
" Преобразовано: " & pageConverted & vbCrLf & _
" Операций Weld: " & pageWeld & vbCrLf & _
" Ошибок: " & pageFailed & vbCrLf & vbCrLf
Next pageIndex
' ==========================================
' 2. Обрабатываем мастер-страницу
' ==========================================
Set textList = New Collection
pageFound = 0
pageConverted = 0
pageWeld = 0
pageFailed = 0
CollectPageText ActiveDocument.MasterPage.shapes, textList
pageFound = textList.Count
foundCount = foundCount + pageFound
For j = textList.Count To 1 Step -1
Set s = textList(j)
If ConvertAndWeldOne( _
s, pageWeld) Then
pageConverted = pageConverted + 1
Else
pageFailed = pageFailed + 1
End If
Next j
convertedCount = convertedCount + pageConverted
weldCount = weldCount + pageWeld
failedCount = failedCount + pageFailed
report = report & _
"Мастер-страница" & vbCrLf & _
" Найдено текстовых объектов: " & pageFound & vbCrLf & _
" Преобразовано: " & pageConverted & vbCrLf & _
" Операций Weld: " & pageWeld & vbCrLf & _
" Ошибок: " & pageFailed & vbCrLf & vbCrLf
' ==========================================
' 3. Завершение
' ==========================================
ActiveDocument.ClearSelection
ActiveDocument.EndCommandGroup
commandStarted = False
MsgBox _
"Обработка завершена!" & vbCrLf & vbCrLf & _
"Найдено текстовых объектов: " & foundCount & vbCrLf & _
"Преобразовано в кривые: " & convertedCount & vbCrLf & _
"Операций Weld: " & weldCount & vbCrLf & _
"Ошибок обработки: " & failedCount & vbCrLf & vbCrLf & _
report, _
vbInformation, "Alltext_to_curve_Svoe"
Exit Sub
ErrorHandler:
errorText = Err.Description
On Error Resume Next
ActiveDocument.ClearSelection
If commandStarted Then
ActiveDocument.EndCommandGroup
End If
On Error GoTo 0
MsgBox _
"Ошибка при обработке документа." & vbCrLf & _
"Страница: " & pageIndex & vbCrLf & _
errorText & vbCrLf & vbCrLf & _
"Найдено: " & foundCount & vbCrLf & _
"Преобразовано: " & convertedCount & vbCrLf & _
"Операций Weld: " & weldCount & vbCrLf & _
"Ошибок отдельных объектов: " & failedCount, _
vbExclamation, "Alltext_to_curve_Svoe"
End Sub
' ==================================================
' Рекурсивный поиск текста в группах и PowerClip
' ==================================================
Private Sub CollectPageText( _
ByVal shapes As shapes, _
ByRef textList As Collection)
Dim s As Shape
Dim pwc As PowerClip
On Error GoTo ExitHere
For Each s In shapes
If s.Type = cdrTextShape Then
textList.Add s
Else
' Поиск внутри групп
If s.Type = cdrGroupShape Then
CollectPageText s.shapes, textList
End If
' Поиск внутри PowerClip
Set pwc = Nothing
On Error Resume Next
Set pwc = s.PowerClip
On Error GoTo ExitHere
If Not pwc Is Nothing Then
CollectPageText pwc.shapes, textList
End If
End If
Next s
ExitHere:
End Sub
' ==================================================
' Преобразование текста и Weld
' Возвращает True, если ConvertToCurves выполнен
' без ошибки.
' ==================================================
Private Function ConvertAndWeldOne( _
ByVal txt As Shape, _
ByRef weldCount As Long) As Boolean
Dim sr As ShapeRange
Dim groupShape As Shape
Dim child As Shape
Dim children As ShapeRange
Dim i As Long
On Error GoTo ItemError
ConvertAndWeldOne = False
' Выбираем текст и преобразуем в кривые
txt.CreateSelection
ActiveSelectionRange.ConvertToCurves
Set sr = ActiveSelectionRange
If sr.Count = 0 Then GoTo ItemError
' ==========================================
' Результат — одна группа
' ==========================================
If sr.Count = 1 Then
Set groupShape = sr(1)
If groupShape.Type = cdrGroupShape Then
Set children = groupShape.shapes.All
For i = 1 To children.Count
Set child = children(i)
If child.Type <> cdrGroupShape Then
child.CreateSelection
If ActiveSelectionRange.Count > 0 Then
ActiveSelectionRange(1).Weld _
ActiveSelectionRange(1), False, False
weldCount = weldCount + 1
End If
End If
Next i
Else
groupShape.CreateSelection
If ActiveSelectionRange.Count > 0 Then
ActiveSelectionRange(1).Weld _
ActiveSelectionRange(1), False, False
weldCount = weldCount + 1
End If
End If
Else
' ==========================================
' Несколько объектов после преобразования
' ==========================================
For i = 1 To sr.Count
Set child = sr(i)
If child.Type <> cdrGroupShape Then
child.CreateSelection
If ActiveSelectionRange.Count > 0 Then
ActiveSelectionRange(1).Weld _
ActiveSelectionRange(1), False, False
weldCount = weldCount + 1
End If
End If
Next i
End If
ConvertAndWeldOne = True
Exit Function
ItemError:
ConvertAndWeldOne = False
End Function