Results 1 to 6 of 6

Thread: Location or Position of any object

  1. #1

    Location or Position of any object

    Hi John,

    Using the similar fashion below, please help me with a code that can pickup location or position of any object on the ppt slide and apply that to another object on the same slide or any other slide.

    Dim adj() As Single 
    Sub PickUp_Ang_Adj() 
        Dim oshp As Shape 
        Dim i As Integer 
    On Error Goto err: 
        Set oshp = ActiveWindow.Selection.ShapeRange(1) 
        Redim adj(1 To oshp.Adjustments.Count) 
        For i = 1 To oshp.Adjustments.Count 
            adj(i) = oshp.Adjustments(i) 
        Next i 
        Exit Sub 
    err: 
        MsgBox "Select Shape" 
    End Sub 
     
    Sub Apply_Ang_Adj() 
        Dim oshp As Shape 
        Dim i As Integer 
    On Error Goto err: 
        For Each oshp In ActiveWindow.Selection.ShapeRange 
            Redim Preserve adj(1 To oshp.Adjustments.Count) 
            For i = 1 To oshp.Adjustments.Count 
                oshp.Adjustments(i) = adj(i) 
            Next i 
        Next oshp 
        Exit Sub 
    err: 
        MsgBox "ERROR" 
    End Sub
    - Thanks
    Last edited by Bob Phillips; 05-06-2014 at 01:29 AM. Reason: Added VBA tags

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,096
    Location
    OK time to start coding yourself!

    Start by adding two more variables at the top of the code (based on the format code you already have)

    Dim sngW As Single
    Dim sngH As Single
    Dim lngRot As Long
    Dim sngL as Single
    Dim sngT as Single

    Use the two new variable to store and apply the oshp.Left and oshp.Top in the same way as Width and Height.

    You can do it!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    wow, thanks John, got the required output.

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,096
    Location
    Maybe post the code to help others.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    Here is the code I used to get the result.

    Dim sngL As Single
    Dim sngT As Single


    Sub Get_Loc()
    Dim oshp As Shape
    On Error GoTo err:
    Set oshp = ActiveWindow.Selection.ShapeRange(1)
    oshp.PickUp
    sngL = oshp.Left
    sngT = oshp.Top
    Exit Sub
    err:
    MsgBox "Select Shape"
    End Sub


    Sub Set_Loc()
    Dim oshp As Shape
    On Error GoTo err:
    For Each oshp In ActiveWindow.Selection.ShapeRange
    oshp.Apply
    oshp.LockAspectRatio = False
    oshp.Left = sngL
    oshp.Top = sngT
    Next oshp
    Exit Sub
    err:
    MsgBox "ERROR"
    End Sub

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,096
    Location
    That's good

    You don't NEED to lock aspect ratio as you are not resizing but it won't do any damage! Pick Up and Apply will pick up and apply other things like fill etc They can be deleted if you don't need this.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •