none
Shape's Left or Top value does not tally for different ways and versions RRS feed

  • Question

  • Hi,

    For below vba code in word:

    Sub iterate_selection()
        For Each shp In Selection.ChildShapeRange
            MsgBox "name: " & shp.Name & vbLf & _
                " & shp.Left & vbLf & _
                " & shp.Top
        Next
    End Sub
    
    Sub iterate_shapes()
        For Each canva In ActiveDocument.Shapes
            If canva.Type = 20 And canva.Name = Selection.ShapeRange.Item(1).Name Then
                For Each shp In canva.CanvasItems
                    If shp.Name = Selection.ChildShapeRange.Item(1).Name Then
                        MsgBox "name: " & shp.Name & vbLf & _
                            " & shp.Left & vbLf & _
                            " & shp.Top
                    End If
                Next
            End If
        Next
    End Sub

    Test by below steps with office 2010 and 2013:

    1. create one canvas
    2. insert any shape in center of the canvas
    3. select the shape just inserted
    4. run the two sub one by another

    Below is my result:


    If left or top value of shape is by points, I think the correct value should be Office 2010 + CavnvasItems, the other values are divided by 20. So what is the consistent way to get left and top values of a shape in word vba?


    • Edited by ocaoms Sunday, October 15, 2017 2:38 AM
    Sunday, October 15, 2017 2:36 AM

All replies

  • Hi ocaoms,

    I could reproduce your issue. I would suggest you go to File->Feedback to submit a feedback for this issue. According to current result, I would suggest you use first part code to get the left and top values.

    Best Regards,

    Terry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 16, 2017 10:14 AM