Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Change buttoncolor on button on a sheet from VBA

Button1.BackColor = &H8000& works ok, but if I make a loop like this

for I = I to 10
if <argument true then
("Button" & cstr(I)).BackColor = &H8000
end if
next

I get this error: Expected : Linenumber or Label or statement or end of statement
how should I call my Button
I tried with:
sheets("sheet1"). ("Button" & cstr(I)).BackColor = &H8000
sheet1. ("Button" & cstr(I)).BackColor = &H8000
activesheet. ("Button" & cstr(I)).BackColor = &H8000
.... and a lot of others
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Change buttoncolor on button on a sheet from VBA

When you reference "button1" as in your first example which works, you are referencing an object. In the non-working other examples you are referencing text, which you can't set to a value.

Try (if the buttons are on a form)
<formname.Controls("Button" & cstr(I))

or if they are on a sheet:
<sheetname.Controls("Button" & cstr(I))

"akyhne" wrote:

Button1.BackColor = &H8000& works ok, but if I make a loop like this

for I = I to 10
if <argument true then
("Button" & cstr(I)).BackColor = &H8000
end if
next

I get this error: Expected : Linenumber or Label or statement or end of statement
how should I call my Button
I tried with:
sheets("sheet1"). ("Button" & cstr(I)).BackColor = &H8000
sheet1. ("Button" & cstr(I)).BackColor = &H8000
activesheet. ("Button" & cstr(I)).BackColor = &H8000
... and a lot of others

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Change buttoncolor on button on a sheet from VBA

I always call my Controls in Forms with me.Controls or <Formname.Controls, but this simply doesn't work on Sheets

"Ian Digby" skrev:

When you reference "button1" as in your first example which works, you are referencing an object. In the non-working other examples you are referencing text, which you can't set to a value.

Try (if the buttons are on a form)
<formname.Controls("Button" & cstr(I))

or if they are on a sheet:
<sheetname.Controls("Button" & cstr(I))

"akyhne" wrote:

Button1.BackColor = &H8000& works ok, but if I make a loop like this

for I = I to 10
if <argument true then
("Button" & cstr(I)).BackColor = &H8000
end if
next

I get this error: Expected : Linenumber or Label or statement or end of statement
how should I call my Button
I tried with:
sheets("sheet1"). ("Button" & cstr(I)).BackColor = &H8000
sheet1. ("Button" & cstr(I)).BackColor = &H8000
activesheet. ("Button" & cstr(I)).BackColor = &H8000
... and a lot of others

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Change buttoncolor on button on a sheet from VBA

sheet1.OLEObjects("Button" & cstr(I)).Object.BackColor = &HFF& works

"akyhne" skrev:

I always call my Controls in Forms with me.Controls or <Formname.Controls, but this simply doesn't work on Sheets

"Ian Digby" skrev:

When you reference "button1" as in your first example which works, you are referencing an object. In the non-working other examples you are referencing text, which you can't set to a value.

Try (if the buttons are on a form)
<formname.Controls("Button" & cstr(I))

or if they are on a sheet:
<sheetname.Controls("Button" & cstr(I))

"akyhne" wrote:

Button1.BackColor = &H8000& works ok, but if I make a loop like this

for I = I to 10
if <argument true then
("Button" & cstr(I)).BackColor = &H8000
end if
next

I get this error: Expected : Linenumber or Label or statement or end of statement
how should I call my Button
I tried with:
sheets("sheet1"). ("Button" & cstr(I)).BackColor = &H8000
sheet1. ("Button" & cstr(I)).BackColor = &H8000
activesheet. ("Button" & cstr(I)).BackColor = &H8000
... and a lot of others

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
Change caption of a button Dylan @ UAFC[_2_] Excel Worksheet Functions 3 November 25th 08 07:04 PM
how to change formula in shared sheet without loss of change histo DCE Excel Worksheet Functions 1 July 23rd 08 05:09 PM
How do I create a command button to jump from sheet to sheet in a. Darlenew Excel Worksheet Functions 3 March 22nd 05 10:36 PM
Change workbook sheet reference using cell A1 to change a vairable Reed Excel Worksheet Functions 4 January 20th 05 07:15 PM
Pause macro, add form button to sheet, continue macro when button clicked! Flystar[_15_] Excel Programming 1 May 26th 04 09:45 AM


All times are GMT +1. The time now is 11:59 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"