ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating References To Excel Objects (https://www.excelbanter.com/excel-programming/311133-re-creating-references-excel-objects.html)

Jim Thomlinson[_3_]

Creating References To Excel Objects
 
No difference in terms of resource. That is just 2 different ways of
accessing the same object. My preference is to change the (Name) property of
the worksheet. This is not the tab Name but rather the VBA (Name). You end up
with something like this:

shtMySheet.Copy
shtMySheet.Range...

By changing the (Name) of the sheet, you can now refer to it directly in
code, and your code is immune to some yahoo coming along and crashing your
code by changing the name of the tabs.

"MDW" wrote:

This may be purely user preference, but not sure.

If I want to refer to an Excel sheet, either of the following formats works
for me:

With objWorkbook.Worksheets("MY SHEET")

.Range("A:A").Select
' Etc.

End With

OR

Set objSheet = objWorkbook.Worksheets("MY SHEET")
With objSheet

.Range("A:A").Select
' Etc.

End With

Any difference (performance, resource use, etc) between the two? Assume that
I have control over sheet names and they will remain constant.
--
Hmm...they have the Internet on COMPUTERS now!



All times are GMT +1. The time now is 01:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com