View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Excel sheet names with spaces

You could protect the workbook's structure so that the user can't change the
name of sheets--but that means that can't move, copy, rename, delete, insert
sheets, either.

Or don't use the name that the user can change.

Instead, use the codename for that sheet.

If you open your workbook, then go into the VBE (alt-f11) and show the project
explorer (hit ctrl-r), you can select your worksheet (expand the branches if you
have to).

Then hit F4 to see the properties window.

You'll see a list of properties including Name and (Name).

The Name property is the name that the user can change on the sheet tab. The
(Name) property is the codename for the sheet.

So instead of having code like:

Worksheets("DCI Data").range("A1").value = "hi there"
you'd use the code name:
Sheet1.range("a1").value = "hi there"

In fact, you can type over the (Name) property with something that is
mnemonically significant. I'd rename that "DCI Data" codename to "DCIData" (no
spaces!).

Then my code would look like:
DCIData.range("A1").value = "hi there"

=====
Be aware that the codename can be changed--you'd want to protect the workbook's
project:

Inside the VBE
Tools|VBAProject Properties|protection tab

And even this protection can be broken for those who really want to.

But it does make it more difficult.



Merlynsdad wrote:

I have a sheet name in Excel that is "DCIdata". The file owner has now
changed it to "DCI Data". I have several references to the sheet in VBA as
DCIdata!. How do I refer to this sheet now that it has a space in it?


--

Dave Peterson