+ Reply to Thread
Results 1 to 3 of 3

Assigning backgroundcolor to button on form

  1. #1
    Brotha lee
    Guest

    Assigning backgroundcolor to button on form

    I have the following code to assign a background color to a button on a
    userform.
    Set Mycmd = Controls.Add("Forms.CommandButton.1", "COL")
    Mycmd.Left = 12
    Mycmd.Top = 70
    Mycmd.Width = 12
    Mycmd.Height = 12
    ActiveSheet.Select
    Mycmd.BackColor = Range(Cells(1, 1)).Interior.color

    This code returns me the error "Method range of _object global failed". When
    I change the line Mycmd.BackColor = Range(Cells(1, 1)).Interior.color to
    Mycmd.BackColor = Range("A1").Interior.color the codes work just fine.

    What is wrong with my code?? As I expect cells(1,1) to be the same as
    range("A1").

    Furthermore I have to have line activesheet.select in the statement to copy
    the colors correctly (when it are colors not from default palette). Does
    anyone know why this part of the code should be included?

    TIA



  2. #2
    Brotha lee
    Guest

    RE: Assigning backgroundcolor to button on form

    Don't bother I fixed the problem. Just stupid me!



    "Brotha lee" schreef:

    > I have the following code to assign a background color to a button on a
    > userform.
    > Set Mycmd = Controls.Add("Forms.CommandButton.1", "COL")
    > Mycmd.Left = 12
    > Mycmd.Top = 70
    > Mycmd.Width = 12
    > Mycmd.Height = 12
    > ActiveSheet.Select
    > Mycmd.BackColor = Range(Cells(1, 1)).Interior.color
    >
    > This code returns me the error "Method range of _object global failed". When
    > I change the line Mycmd.BackColor = Range(Cells(1, 1)).Interior.color to
    > Mycmd.BackColor = Range("A1").Interior.color the codes work just fine.
    >
    > What is wrong with my code?? As I expect cells(1,1) to be the same as
    > range("A1").
    >
    > Furthermore I have to have line activesheet.select in the statement to copy
    > the colors correctly (when it are colors not from default palette). Does
    > anyone know why this part of the code should be included?
    >
    > TIA
    >
    >


  3. #3
    Zack Barresse
    Guest

    Re: Assigning backgroundcolor to button on form

    I suspect that "color" should be "colorindex". Was this the case?

    Good to see you figured it out though!

    --
    Regards,
    Zack Barresse, aka firefytr

    "Brotha lee" <Brothalee@discussions.microsoft.com> wrote in message
    news:2B2FE582-AA5D-4F8B-9E11-FE7021A58AEF@microsoft.com...
    > Don't bother I fixed the problem. Just stupid me!
    >
    >
    >
    > "Brotha lee" schreef:
    >
    >> I have the following code to assign a background color to a button on a
    >> userform.
    >> Set Mycmd = Controls.Add("Forms.CommandButton.1", "COL")
    >> Mycmd.Left = 12
    >> Mycmd.Top = 70
    >> Mycmd.Width = 12
    >> Mycmd.Height = 12
    >> ActiveSheet.Select
    >> Mycmd.BackColor = Range(Cells(1, 1)).Interior.color
    >>
    >> This code returns me the error "Method range of _object global failed".
    >> When
    >> I change the line Mycmd.BackColor = Range(Cells(1, 1)).Interior.color to
    >> Mycmd.BackColor = Range("A1").Interior.color the codes work just fine.
    >>
    >> What is wrong with my code?? As I expect cells(1,1) to be the same as
    >> range("A1").
    >>
    >> Furthermore I have to have line activesheet.select in the statement to
    >> copy
    >> the colors correctly (when it are colors not from default palette). Does
    >> anyone know why this part of the code should be included?
    >>
    >> TIA
    >>
    >>




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1