loct
loct

Reputation: 367

When does the activeworkbook/activesheet change?

I have some questions about the activeworkbook/activesheet properties, would appreciate your help:

  1. In any instances, there would be at maximum only one activeworkbook or no, and that applies to activesheet. Is that right?

  2. If properties like ranges,cells,... are not fully qualified when used, they are by default meant to be that of the activeworkbook.activesheet. Is that right?

  3. Will the activeworkbook change to another workbook by vba actions other than activating the other workbook?

  4. When I use wb.ws.range(cells(x1,y1),cells(x2,y2)), are the cells implied to be the cells of wb.ws? Or do they need to be qualified?

  5. Is it possible to run the vba codes stored in the modules of a workbook without activating the workbook?

Thank you.

Upvotes: 2

Views: 310

Answers (1)

Siddharth Rout
Siddharth Rout

Reputation: 149335

In any instances, there would be at maximum only one activeworkbook or no, and that applies to activesheet. Is that right?

Yes. .ActiveWorkbook returns a Workbook object that represents the workbook in the active window (the window on top).

If properties like ranges,cells,... are not fully qualified when used, they are by default meant to be that of the activeworkbook.activesheet. Is that right?

Yes

Debug.Print rng.Parent.Name '<~~ This will give you the name

Will the activeworkbook change to another workbook by vba actions other than activating the other workbook?

Yes it is possible. For example if you send your Active Workbook to Back or minimise it then if the next window in zOrder is a workbook then that will get activated

When I use wb.ws.range(cells(x1,y1),cells(x2,y2)), are the cells implied to be the cells of wb.ws? Or do they need to be qualified?

Only if ws is active then yes else they will refer to Activesheet and hence it is always good to fully qualify your objects

With ws
    Set Rng = .Range(.Cells(x1, y1), .Cells(x2, y2))
End With

Is it possible to run the vba codes stored in the modules of a workbook without activating the workbook?

Yes. You can use Application.Run

Upvotes: 1

Related Questions