Consulting

Results 1 to 18 of 18

Thread: Solved: Shapes: Some Explanation Please

  1. #1

    Solved: Shapes: Some Explanation Please

    This is for pure learning reasons, no project.
    All of the following code is from the help file. I am curious about certain objects and properties that I have not used to become familiar.

    In this case wanted to see what .List was about, which took me to Shapes.
    I could not get enough information about .List, so I went onto Shapes.

    My interest is purely about worksheet shapes, not charts.
    Examples 1,2,3, and 4 are where my questions lie.
    Examples 5 and 6 were successful.

    I have two shapes on my worksheet, drawn from the tools on the Drawing Toolbar.

    Ex.2 refers to Shapes(1). I looked for properties on the sheet of the shapes to see how these were referenced. I could not find any where that referes to the properties of these created shapes.
    So when it is instructing the shape to be flipped, how is it referencing a particuluar shape.

    Ex.3 & 4 refer to the shape by name "Rectangle 1", same basic questions.
    How is this shape referenced by this name?

    [vba]
    Sub test()
    'ex.1
    Worksheets(1).Shapes(2).ControlFormat.List = _
    Array("cogs", "widgets", "sprockets", "gizmos")
    Application.AddCustomList Array("cogs", "sprockets", _
    "widgets", "gizmos")
    'ex.2
    Set myDocument = Worksheets(1)
    myDocument.Shapes(1).Flip msoFlipHorizontal
    myDocument.Shapes("Rectangle 1").Flip msoFlipHorizontal
    'ex.3
    Worksheets(1).Shapes(1).Flip msoFlipHorizontal
    'ex.4
    Worksheets(1).Shapes("Rectangle 1").Flip msoFlipHorizontal
    'ex.5
    Worksheets(1).Shapes(1).Fill.ForeColor.RGB = RGB(255, 255, 0)
    'ex.6
    Set myDocument = Worksheets(1)
    With myDocument.Shapes.AddShape(msoShapeRightTriangle, _
    10, 10, 50, 50).Duplicate
    .Fill.ForeColor.RGB = RGB(255, 0, 0)
    .Flip msoFlipVertical
    End With
    End Sub
    [/vba]

    thanks.....
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Hint.

    Shapes are not just charts and items on the drwaing toolbar.

    A Forms Listbox is also a shape for example.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Ok.... I will pursue that thought.

    In the mean time, a few followup questions regarding the example posted plz.

    In ex.6- it flips only one of the new shapes, the duplicated triangle- how does the code choose which one of the two shapes apply the instructions, to flip, or color the duplicated shape and not the first shape?

    It colors the first shape maroon, and the duplicated triangle yellow. I don't see where the code is getting this information to fill either of them w/ maroon, is code using the last color used? Filling w/ yellow RGB(255, 255,0) is understood, but again as in the first follow-up question here how does it choose- same answer will apply here....

    Lastly- depending on your answers to the above questions, this may become evident;
    How would I reference the first shape if I wanted to provide instructions specific to this shape rather than the latter?
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  4. #4
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    This line:
    [vba]myDocument.Shapes.AddShape[/vba] adds a shape and returns a shape object to the code. You then apply the Duplicate method to this object, which creates a copy of it and returns a reference to that copy. That is the object being used by everything in the With...End With block. I don't see anything about purple in there.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Hello Rory,
    That was my assumption,
    That is the object being used by everything in the With...End With block.
    If that is how it handles it, is there a means to identify a Shapes object to manipulate it?

    thanks....
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Only by setting a variable to it whne creating, and using that.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Or if you know its name, or it has some unique identifying characteristic.
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    Rory,
    Can you provide an example?
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  9. #9
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Well, if you know its name, you can just refer to that, as in your example 4. If you know that it is the only dropdown, or of any other type, you can loop through the collection checking the Type and/or AutoShapeType of each shape to find the one you want. You can do the same with TopLeftCell property if you know where your shape is, and so on. Obviously, if you create the shape, it's easiest to just grab a reference to it then.
    Regards,
    Rory

    Microsoft MVP - Excel

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The easiest way has to be to set the variable as you create it as I said earlier, and give it a meaningful name. You then have full control.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    Thanks Bob and Rory.
    Here is wherein the problem resided- (resided, b/c now I get it).
    I wanted to flip a shape. (My thought of what Flip is and VBA's was definitely different).
    I had a rectangle, its position was vertical. The .flip msoFlipHorizontal was not flipping it horizontally. The shape was not ending up on a different axis.
    I thought the code was not identifying the shape, (my confusion started here). So I thought I needed to know some property that would identify the shape. I started looking for properties.

    [Bob- I was not using your solution just yet b/c the shape already existed and the question going around in my head was if the shape exists, how do I reference it.]

    [Rory, the name "Rectangle 1" does not seem to be doing anything.]

    The code in fact was identifying it and was flipping it, but whatever .flip msofliphorizontal means to a rectangle shape I still do not understand, b/c the final appearance does not look any different from whence it began. Maybe it means flip it over, front to back.... I will play w/ this more later.

    So how I tested it was to manually select the shape and rotate it slightly. Then running the code, the shape's position was altered.
    I also did a simple .Select command, this worked, then it started to fall into place.
    I looked for how to rotate it a certain number of degrees and this is what I found:
    Using:
    [VBA]
    Worksheets("Sheet1").Shapes("Rectangle 1").IncrementRotation 90#
    [/VBA]
    Alters the shape's position.

    In closing what I was looking to do solve that did not require any solving.
    Bob and Rory, your solutions were right on the money- but I could not see it.

    Thanks for hanging w/ me on this.

    Best regards,

    Doug
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This flips fine for me

    [vba]

    Dim shp As Shape
    Set shp = ActiveSheet.Shapes.AddShape(msoShapeRightTriangle, 10, 10, 50, 50)
    shp.Flip msoFlipVertical
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  13. #13
    Me too, but not rectangles.... can you test it on a rectangle?
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    But a rectangle (or more precisely a square) is the same when flipped.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  15. #15
    Nope, have to respectfully disagree.
    Only in theory, not from practical standpoint, b/c obviously I am incorrect.
    My perspective is if a rectangle is instructed to be flipped, it would be be altered to that position, horizontal or vertical.
    Anyway- I think I am howling at the moon on this one....
    (btw: I wrote this, knowing very likely I am going to get schooled here.... <G>)
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  16. #16
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Take a playing card. Hold a pencil across its midpoint (either horizontal or vertical) and rotate the card around around the pencil. It produces the same shape, no?
    Regards,
    Rory

    Microsoft MVP - Excel

  17. #17
    Rory-
    Yep. Before I say anymore, let me mess w/ this some.
    my site: www.ecboardco.com
    was built w/ a majority of the assistance from the board members here... thanks VBAX.

    Just because I see something, doesn't mean that what's actually happening is what I see.

    You don't get from 0-90 by standing still!

  18. #18
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Hi YellowLabPro,

    I can see where the possible confusion is coming from. The 2 Flip icons would suggest that the flipping is done on a edge of the shape where as in fact the flipping and rotation is done around the center point of the shape.
    Cheers
    Andy

Posting Permissions

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