Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
hi,all:
I face a problem, I have a button control in worksheet 2, and the code as below: Private Sub CommandButton1_Click() Worksheets(1).Activate Cells(1, 1).Value = "kk" End Sub and It seems that worksheet 1 is activated ,but kk is set at the worksheet 2's cell (1,1) not at the worksheet 1. It seems that the defaultworksheet is not the active worksheet. It is so strange. Why it is so? many thanks, PanTao |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If the code is in a general module, then the unqualified range belongs to the
activesheet. If the code is behind a worksheet (and it is in your case), then the unqualified ranges belong to the object owning the code -- the sheet with the commandbutton. Private Sub CommandButton1_Click() Worksheets(1).Activate 'you don't even need this line! worksheets(1).Cells(1, 1).Value = "kk" End Sub pt wrote: hi,all: I face a problem, I have a button control in worksheet 2, and the code as below: Private Sub CommandButton1_Click() Worksheets(1).Activate Cells(1, 1).Value = "kk" End Sub and It seems that worksheet 1 is activated ,but kk is set at the worksheet 2's cell (1,1) not at the worksheet 1. It seems that the defaultworksheet is not the active worksheet. It is so strange. Why it is so? many thanks, PanTao -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Oh,I see, it is reasonable, many thanks ,Dave. And I had search the help of
EXCEL VBA reference, but did't find it, all the explaination I found is that the unqualified range belongs to the activesheet. May you tell me Where can I find it?Many Thanks. PanTao -------------------------------------- "Dave Peterson" ... If the code is in a general module, then the unqualified range belongs to the activesheet. If the code is behind a worksheet (and it is in your case), then the unqualified ranges belong to the object owning the code -- the sheet with the commandbutton. Private Sub CommandButton1_Click() Worksheets(1).Activate 'you don't even need this line! worksheets(1).Cells(1, 1).Value = "kk" End Sub pt wrote: hi,all: I face a problem, I have a button control in worksheet 2, and the code as below: Private Sub CommandButton1_Click() Worksheets(1).Activate Cells(1, 1).Value = "kk" End Sub and It seems that worksheet 1 is activated ,but kk is set at the worksheet 2's cell (1,1) not at the worksheet 1. It seems that the defaultworksheet is not the active worksheet. It is so strange. Why it is so? many thanks, PanTao -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I've never looked for it.
But you can see it yourself. Change your code (temporarily) to: Private Sub CommandButton1_Click() Worksheets(1).Activate msgbox Cells(1, 1).parent.name End Sub (make sure that the worksheet with the button is not worksheets(1), though.) pt wrote: Oh,I see, it is reasonable, many thanks ,Dave. And I had search the help of EXCEL VBA reference, but did't find it, all the explaination I found is that the unqualified range belongs to the activesheet. May you tell me Where can I find it?Many Thanks. PanTao -------------------------------------- "Dave Peterson" ... If the code is in a general module, then the unqualified range belongs to the activesheet. If the code is behind a worksheet (and it is in your case), then the unqualified ranges belong to the object owning the code -- the sheet with the commandbutton. Private Sub CommandButton1_Click() Worksheets(1).Activate 'you don't even need this line! worksheets(1).Cells(1, 1).Value = "kk" End Sub pt wrote: hi,all: I face a problem, I have a button control in worksheet 2, and the code as below: Private Sub CommandButton1_Click() Worksheets(1).Activate Cells(1, 1).Value = "kk" End Sub and It seems that worksheet 1 is activated ,but kk is set at the worksheet 2's cell (1,1) not at the worksheet 1. It seems that the defaultworksheet is not the active worksheet. It is so strange. Why it is so? many thanks, PanTao -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Default Settings for a New Worksheet | Excel Discussion (Misc queries) | |||
Making a worksheet default | Excel Discussion (Misc queries) | |||
How To Open First Worksheet By Default? | Excel Discussion (Misc queries) | |||
default excel worksheet | Excel Discussion (Misc queries) | |||
Trying to set default Worksheet file name from C++/MFC | Excel Programming |