Consulting

Results 1 to 4 of 4

Thread: Problem with ActiveSheet.Shapes

  1. #1

    Problem with ActiveSheet.Shapes

    When I combine two statements into one, it doesn't work. What's the problem here:
    Sub TestPhfft()
    'The next 2 lines work OK
    ActiveSheet.Shapes("Rectangle 3").Select
    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 3
    'The next line gets a Runtime Error 438:
    '  "Object doesn't support this property or method"
    ActiveSheet.Shapes("Rectangle 3").ShapeRange.Fill.ForeColor.SchemeColor = 3
    End Sub

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    This works:


    Sub TestPhfft() 
        ActiveSheet.Shapes("Rectangle 3").Fill.ForeColor.SchemeColor = 3 
    End Sub 
    All I did was get rid of the ShapeRange....Don't ask me why/how it works, I just took a lucky guess




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    In the first piece of code you are expanding the shape out to the selection and, to focus back in on the shape in the second statement, must use the selection's shaperange. When combining the two statements you are not selecting, and already have a reference to the shape, so can go directly to the fill - as shown by Joseph.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  4. #4
    Tony, I think you've got it. I had a feeling it was something like that ... just don't have the smarts to know what it was exactly. Thanks!
    And thanks to Joseph for figuring out what to do.

Posting Permissions

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