English 中文(简体)
“VBA Corel 引文“A-Z不是为了”
原标题:"VBA CorelDraw "Rename Object A-Z not in order

I have created a script to rename objects in CorelDraw according to alphabetical order. This script should work as expected, but I don t know why the sequence is from Z to A. Screenshots on the left show the code functioning as intended.

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的次序?

问题回答
  • Since I don t have CorelDRAW software, I m uncertain whether this issue is related to the sequence in which users select multiple shapes.
  • Referring to your screenshot, the code could be revised as follows.
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




相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签