excel - VBA - When to specify ActiveWorkbook -
when writing vba code, if know you're going operating in same workbook , on worksheet, should specify activeworkbook workbook objects in code there? example:
activeworkbook.sheets("sheet1").range("$a$1")
vs
range("$a$1")
above code assumes working off of sheet1 through local macros(under sheet1 object in vba).
better using activeworkbook in situations using workbooks("book1") more specific , robust , believe faster execute activating workbook , pointing when referencing ranges.
the vba default last active workbook if not designate 1 when using lines of code range("a1") if working in 1 workbook not necessary since last active workbook should workbook want code execute in. typically designate sheets , ranges when i'm working in single workbook since little redundant tell excel select active workbook when default in absence of specific workbook designation.
just make sure running macro open workbook want code execute in.
including workbook designation never hurt , make code more robust. if ever have code execute in single workbook not necessary.
Comments
Post a Comment