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