1
所以我有一個宏來搜索文檔上的所有文本並將它們全部轉換爲曲線。該宏還會查看超出CQL範圍的powerclip。引用的對象不再存在?
下面是我的代碼:
Public Sub convertText()
Dim pg As Page
Dim shRange As ShapeRange
Dim sh As Shape
For Each pg In ActiveDocument.Pages
pg.Activate
Set shRange = FindAllPCShapes.Shapes.FindShapes(Query:="@type='text:artistic' or @type='text:paragraph'")
For Each sh In shRange
sh.ConvertToCurves
Next sh
Next pg
End Sub
Function FindAllPCShapes(Optional LngLevel As Long) As ShapeRange ' Shelby's function
Dim s As Shape
Dim srPowerClipped As New ShapeRange, srJustClipped As New ShapeRange
Dim sr As ShapeRange, srAll As New ShapeRange
Dim bFound As Boolean, i&
bFound = False
If ActiveSelection.Shapes.count > 0 Then
Set sr = ActiveSelection.Shapes.FindShapes()
Else
Set sr = ActivePage.Shapes.FindShapes()
End If
i = 0
Do
For Each s In sr.Shapes.FindShapes(Query:="[email protected]")
srPowerClipped.AddRange s.PowerClip.Shapes.FindShapes()
Next s
If srPowerClipped.count > 0 Then bFound = True: i = i + 1
If i = LngLevel And bFound Then Set FindAllPCShapes = srPowerClipped: Exit Function
bFound = False
srAll.AddRange sr
sr.RemoveAll
sr.AddRange srPowerClipped
If LngLevel = -1 Then srJustClipped.AddRange srPowerClipped
srPowerClipped.RemoveAll
Loop Until sr.count = 0
If LngLevel = -1 Then
Set FindAllPCShapes = srJustClipped
Else
Set FindAllPCShapes = srAll
End If
End Function
它工作正常,在某些情況下,但我的一些文件,其中對於每個SH在shRange將產生一個錯誤「被引用的對象已不存在」抓住了一個錯誤。顯然這是因爲powerclip中的嵌套組。
我試圖通過添加On Error Resume Next來忽略錯誤,宏將運行良好。但是我當然想知道我的代碼有什麼錯誤,所以我可以避免將來的麻煩,我寧願不忽略宏中的所有錯誤。
下面是一個演示錯誤的示例文檔。 https://www.dropbox.com/s/lpi568eoltc8cxy/ReferenceError.cdr?dl=0
謝謝
都能跟得上仍然沒有做任何事情,foreach循環內發生的錯誤,以便它永遠不會檢查shRange是沒有什麼再一次它在循環中。 –
沒有CorelDraw測試你的文件,基於它的語法可能是'For Shr in shRange.Shapes'? – PatricK