none
Understanding the properties of an object RRS feed

  • Question

  • I am trying to create objects (buttons) using excel VBA so I use a macro to do this so I can understand the coding.

    I got this:

     ActiveSheet.Shapes.AddShape(msoShapeRoundedRectangle, 771.75, shp, 46.5, 10.5 _

            ).Select

    I change “z” property to “shp” so I can create multiple objects in different rows.

    So, the first number is “x” location and the second is “y” location what is the third and for number?

    I assume is the size of the object and if it is does not correlate with object when you select the object end select “size and properties.

    Also after I create a object how can I find this properties (x,y,w,h)

    Thank you,

    Kosta


    Vforum

    Friday, October 18, 2019 12:41 PM

Answers

  • The syntax of AddShape is

    Function AddShape(Type As MsoAutoShapeType, Left As Single, Top As Single, Width As Single, Height As Single) As Shape

    The arguments you ask about are the width and height of the shape. Like the left and top properties, they are expressed in points, where 1 inch = 72 points.

    So in your example. the width of the rectangle is 46.5 points = 0.64 inches, and the height is 10.5 points = 0.15 inches.

    If you want to specify any of these arguments in inches or centimeters, you can use the Application.InchesToPoints / Application.CentimetersToPoints functions. For example, to specify a width of 0.8 inch, use Application.InchesToPoints(0.8)

    A Shape object has properties Left, Top, Width and Height. These return the value in points. To convert these to inches, divide by 72:

        Dim MyShape As Shape
        Set MyShape = ActiveSheet.Shapes(1)
        MsgBox "The width of the shape is " & MyShape.Width / 72 & " inches"


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Kosta si Friday, October 18, 2019 10:07 PM
    Friday, October 18, 2019 2:35 PM
  • thank you that make a sense,

    i figure that those two number in the end are the dimensions of the object but I didn’t know they are points.

    is points the same as pixels? or not? that will help me size the image that i am using to fit into the object.


    Kosta

     

    Vforum


    • Edited by Kosta si Friday, October 18, 2019 2:48 PM
    • Marked as answer by Kosta si Friday, October 18, 2019 10:07 PM
    Friday, October 18, 2019 2:47 PM
  • No, points are not the same as pixels. The size of a pixel depends on the resolution of your screen.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Kosta si Friday, October 18, 2019 10:07 PM
    Friday, October 18, 2019 9:05 PM
  • thank you,

    Kosta


    Vforum

    • Marked as answer by Kosta si Friday, October 18, 2019 10:07 PM
    Friday, October 18, 2019 10:07 PM

All replies

  • The syntax of AddShape is

    Function AddShape(Type As MsoAutoShapeType, Left As Single, Top As Single, Width As Single, Height As Single) As Shape

    The arguments you ask about are the width and height of the shape. Like the left and top properties, they are expressed in points, where 1 inch = 72 points.

    So in your example. the width of the rectangle is 46.5 points = 0.64 inches, and the height is 10.5 points = 0.15 inches.

    If you want to specify any of these arguments in inches or centimeters, you can use the Application.InchesToPoints / Application.CentimetersToPoints functions. For example, to specify a width of 0.8 inch, use Application.InchesToPoints(0.8)

    A Shape object has properties Left, Top, Width and Height. These return the value in points. To convert these to inches, divide by 72:

        Dim MyShape As Shape
        Set MyShape = ActiveSheet.Shapes(1)
        MsgBox "The width of the shape is " & MyShape.Width / 72 & " inches"


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Kosta si Friday, October 18, 2019 10:07 PM
    Friday, October 18, 2019 2:35 PM
  • thank you that make a sense,

    i figure that those two number in the end are the dimensions of the object but I didn’t know they are points.

    is points the same as pixels? or not? that will help me size the image that i am using to fit into the object.


    Kosta

     

    Vforum


    • Edited by Kosta si Friday, October 18, 2019 2:48 PM
    • Marked as answer by Kosta si Friday, October 18, 2019 10:07 PM
    Friday, October 18, 2019 2:47 PM
  • No, points are not the same as pixels. The size of a pixel depends on the resolution of your screen.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Kosta si Friday, October 18, 2019 10:07 PM
    Friday, October 18, 2019 9:05 PM
  • thank you,

    Kosta


    Vforum

    • Marked as answer by Kosta si Friday, October 18, 2019 10:07 PM
    Friday, October 18, 2019 10:07 PM