View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
[email protected] HammerJoe@gmail.com is offline
external usenet poster
 
Posts: 126
Default Why doesnt this work?

Hi,

I've tried several variations and it doesnt work.
Tim explanation makes sense and explains this weird behaviour.


One last question about this subject just for my future reference.
I have this code that works:

Dim lb As Object
'Add Items to list
Dim X As Long

With Sheets("Main")
Set lb = .ListBoxCross
lb.Clear
lb.AddItem "Not Attempted"
end with

If I was going to use the OLEObjects(" where would it be used?

Thanks

On Feb 9, 9:43*pm, JLGWhiz wrote:
I'll play dumb and ask if you are running your code from a personal workbook
and trying to set a variable in the active workbook. *If so, it won't work
with the ThisWorkbook reference, since ThisWorkbook is the one with the code
running.



" wrote:
Dim MainWorksSheet As Worksheet
Set MainWorksSheet = ThisWorkbook.Worksheets("Main") *Yes the
worksheet is named Main.


MainWorksSheet.CommandButtonAdd.Enabled = True
MainWorksSheet.CommandButtonMakeBusy.Caption = "Start"


**Both being a button created with the control toolbox.


I get the error : Method or Data member not found.


On the other hand :


ActiveSheet.CommandButtonAdd.Enabled = True
ActiveSheet.CommandButtonMakeBusy.Caption = "Start"


Works fine! Unless the focus is on a different sheet named something
else.


I need to make sure that it refers to the sheet "Main" because I have
other sheets and if they have the focus then the ActiveSheet doesnt
work either.
Thanks for any help.