Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default 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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning A Macro to A Button Holly Excel Worksheet Functions 1 January 18th 08 10:04 AM
Change backgroundcolor wborg Excel Discussion (Misc queries) 2 December 1st 05 02:13 AM
Assigning macro to button d Excel Discussion (Misc queries) 0 August 22nd 05 01:40 PM
Assigning a macro to a "button" Yvon Excel Discussion (Misc queries) 6 February 8th 05 10:58 PM
Assigning name to button Grant Reid Excel Programming 4 June 3rd 04 08:55 AM


All times are GMT +1. The time now is 10:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"