我创建了一个脚本来根据字母顺序重命名 CorelDraw 中的对象。该脚本应该按预期工作,但我不知道为什么顺序是从 Z 到 A。
Sub RenameSelectedObjects()
Dim i As Integer
Const START_CHAR = 65 ' ASCII untuk 'A'
Const END_CHAR = 90 ' ASCII untuk 'Z'
Dim objCount As Integer
Dim selectedShape As Shape
i = 0
objCount = ActiveSelectionRange.Count
For Each selectedShape In ActiveSelectionRange
If i > END_CHAR - START_CHAR Then Exit Sub
selectedShape.Name = Chr(START_CHAR + i)
i = i + 1
Next selectedShape
End Sub
但是,如果“对象作为一个整体”通过此脚本成功,那就是另一回事了。
Sub RenameObjects()
Dim i As Integer
Const START_CHAR = 65 ' ASCII untuk 'A'
Const END_CHAR = 90 ' ASCII untuk 'Z'
i = 0
For Each s In ActivePage.Shapes.All
If i > END_CHAR - START_CHAR Then Exit Sub
s.Name = Chr(START_CHAR + i)
i = i + 1
Next s
End Sub
有谁可以帮助我使脚本仅适用于选定的对象并保持它们从 A 到 Z 的顺序吗?
Sub RenameSelectedObjects()
Dim i As Integer
Const START_CHAR = 65 ' ASCII untuk 'A'
Const END_CHAR = 90 ' ASCII untuk 'Z'
Dim objCount As Integer
Dim selectedShape As Shape
i = 0
objCount = ActiveSelectionRange.Count
If objCount > END_CHAR - START_CHAR Then objCount = END_CHAR - START_CHAR ' **
For Each selectedShape In ActiveSelectionRange
selectedShape.Name = Chr(START_CHAR + objCount - i) ' **
i = i + 1
If i > END_CHAR - START_CHAR Then Exit Sub
Next selectedShape
End Sub