Notification texts go here Contact Us Buy Now!

BatchReplaceShapesKeepScale_VBA_CorelDRAW

KHTM

 ទីមួយសូមជ្រើសរើស រូបភាពដែលចង់ផ្លាស់ប្ដូរជាមុន បន្ទាប់មកសូមជ្រើសរើសរូបភាពទាំងអស់ដែលត្រូវផ្លាស់ប្ដូរ។ Shift + Click Selection




Option Explicit
Sub BatchReplaceShapesKeepScale()
    Dim doc As Document
    Set doc = ActiveDocument
    
    ' Check if at least 2 objects are selected
    If doc.Selection.Shapes.Count < 2 Then
        MsgBox "Please select all old shapes first, then Shift + Click the new shape last!", vbExclamation, "BITEPOINT DATA"
        Exit Sub
    End If
    
    Dim sourceShape As Shape
    Dim targetShape As Shape
    Dim newShape As Shape
    Dim i As Long
    Dim selCount As Long
    Dim selSet As ShapeRange
    
    Set selSet = doc.SelectionRange
    selCount = selSet.Count
    
    ' The last selected item is the master Source Shape
    Set sourceShape = selSet(selCount)
    
    doc.BeginCommandGroup "Exact Replace Keep Scale"
    
    Optimization = True
    
    For i = 1 To selCount - 1
        Set targetShape = selSet(i)
        
        Dim origCX As Double, origCY As Double
        Dim origRot As Double
        
        ' 1. Get exact Center position and Rotation Angle of old shape
        origCX = targetShape.CenterX
        origCY = targetShape.CenterY
        origRot = targetShape.RotationAngle
        
        ' 2. Duplicate the new source shape
        Set newShape = sourceShape.Duplicate
        
        ' 3. Apply exact rotation of the old shape
        newShape.RotationAngle = origRot
        
        ' 4. Align Center to Center (100% exact without affecting scale)
        newShape.SetPositionEx cdrCenter, origCX, origCY
        
        ' 5. Delete the old shape
        targetShape.Delete
    Next i
    
    Optimization = False
    ActiveWindow.Refresh
    
    doc.EndCommandGroup
End Sub

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.
/* Calculate Coil Length-Meter */ /* Calculate Coil Length-Meter-function */