Thread: macro question
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default macro question

It depends on how you refer to that worksheet.

If you use the name of the sheet that you see on the tab, then nope.

Worksheets("Accounting Info").range("a1").value = "hi there"
will break.

But each sheet has its own code name--you can see it in the VBE when you show
the project explorer (and expand the branches).

With my example name, you'd see something like:
Sheet1(Accounting Info)

The name in ()'s is what the user sees in the sheet tab.

The name in front of this is called the codename. You can change this to a nice
mnemonically significant name and use it in your code. Although this codename
can be changed, most users wouldn't know how.

Open the VBE (alt-F11)
Open the project Explorer (ctrl-r)
Expand the project
Select the object under: Microsoft Excel Objects
that represents your worksheet.

Hit F4 to show the properties window.
In the (Name) box, give it a nice name -- like:
AcountingInfo

Then you can use something like this in your code:
AccountingInfo.range("a1").value = "hi there"

You don't have to rename the codename, but things like this can get very
confusing:

Sheet1.range("a1").value = "hi there"
Sheet2.range("a1").value = "bye there"
Sheet3.range("a1").value = "welcome back"
Sheet4.range("a1").value = "gone again?"




Oligo wrote:

if my macro on sheet 2 has a formula reference with sheet 1 cell, when i
change the name of sheet 1, will the macro work and change itself
accordingly???


--

Dave Peterson