How to get the OBJECT name of a Worksheet? - object

I need to work with the OBJECT names of the Worksheets in my Workbook, because even if the user changes the Worksheet name, I still could find it using the OBJECT name.
In the image below, all Worksheets have their "given name" and their Object name. See the highlighted one: It's given name is "Doppler Brachial", and it's Object name is "Planilha13" ("Worksheet13" in Portuguese). Even if the user changes the "Doppler Brachial" to "DpBr Analitical" (for example), I could still locate the necessary data by referring to "Planilha13".
Any aideas? Thanks in advance!

I was so anxious that I missed a step...
Instead of using Sheet(n).Name (wich will give-me the index name "Doppler Brachial" of the worksheet), i should use Sheet(n).CodeName.
That picks the "Planilha13" name, the one that does not change, regardless of the Worksheet name or its position.
Thanks anyway! Best regards!

Related

Suppress the message during copy or rename action for a Worksheet that has a Define Names inside

Is there any way to eliminate the message we get when we want to create a new Worksheet (Right button on the Worksheet tab, then select: (Move or Copy...)
and for the Worksheet we want to create a copy has defined some formula inside, so we get the following message:
I don't want to redefine the existing formula names, so I always will take the same action: Yes. In my case, the formula DoneDays was defined in the Worksheet I wanted to copy.
I would like to eliminate this message because I have several formulas/names per sheet, so it is a little annoying to get always such kind of message.
I guess I found the reason of this problem. After deleting the names that have as value #REF! de problem disappears. There is an image in the question for Manager Names view that shows for example that for the name: DoneDays with Workbook scope it has this invalid value. After deleting all such names the copy/paste process works fine.

Excel doesn't release a shape's creation name

I’m posting this in the hope that it might help someone else, as none of my searches revealed any information regarding this.
I ran into this while building a procedure that would copy an imbedded form shape, and paste it on the same sheet, then run a renaming scheme that would facilitate referencing either of these shapes
This should be simple enough, but I was running into an intermittent problem. Eventually I came to realize that Excel appears to “remember” the shape’s original name at the time of its creation, and keeps it flagged as being in use, releasing it only when the shape is deleted. So if you rename the shape, you can never return it to the original name. E.g., if you rename “Button 1” to “Btn1”, you can never change it back to “Button 1”. Interestingly, you can now reference the shape by either name, “Button 1” or “Btn1”.
In the macro below, assuming “Button 1” is the creation name, s.Name will end up as “Btn1”, even though it looks like it would return to “Button 1”.
Sub RenameShape()
Dim s As Shape
Dim nm As String
Set s = ActiveSheet.Shapes("Button 1")
nm = s.Name
s.Name = "Btn1"
s.Name = nm
End Sub
I have since come across a couple of links that talk about the shape’s “internal” and “external” names – I’m assuming the “internal” name is the inaccessible one that Excel won’t forget, while the “external” name is the exposed name that one normally sees.
I’d be interested to hear from anyone who can shed more insight into this.
As the main purpose of this post was to pass along information, I'm going to make this an answer so it can be closed.

Identifying a worksheet other than by its name

A worksheet can be identified by its name such as in this example:
Dim mysheet As Worksheet
Set mysheet = ThisWorkbook.Sheets("My Sheetname")
Now I wonder if a worksheet can be identified other than by its name, for example by some unique id or some property or whatever.
My problem is following:
Referring to the code snippet above: if a user changes the name of the worksheet (e.g. from "My Sheetname" to "Your Sheetname"), the snippet obviously won't work anymore.
This is a very good article that explains that it is better to use the SheetID (also called codename) instead of the Sheet Name.
Quoting:
The Codename property is the internal name that Excel uses to identify
each sheet. Unlike the Worksheet.Name property, the Codename remains
the same regardless of sheet name, or sheet order.
The code name can also be changed so that it is more descriptive:
ThisWorkbook.VBProject.VBComponents("Sheet1").Name = "Revenue_Actuals"
and then
Revenue_Actuals.Range("C2").value = 10
works fine.
Using codenames (such as Sheet1.Range("C1").value) is a good idea, however changing code names at runtime as above is not considered good practice by some developers (see for example, comments on the article of the link above).
Using the sheet index is another way to go, but I personally prefer the code name.
Finally, this article lists many ways that a sheet or workbook can be referenced.
I hope this helps!
You can just access them by index like e.g. for the second sheet
Set mysheet = ThisWorkbook.Sheets(2)

In AppleScript how to you retrieve the name of the current active worksheet?

It seems like a simple question, but much use of Google has not yielded the answer.
Consider the following code...
tell application "Microsoft Excel"
set strActiveWorkSheet to active sheet of active workbook
display dialog strActiveWorkSheet
end tell
This code does not work. It seems that the set command is setting strActiveWorkSheet to a object that represents the Active Worksheet.
Maybe I'm on the wrong track here but the questions remains...
How to I retrieve the name of the current active Excel worksheet?
Funny... your question is the answer... just get its name. You're right. You have an object the way its written and the object has properties, one of which is "name". In other words change this line...
set strActiveWorkSheet to name of active sheet of active workbook
To see all of the properties of the object try this...
tell application "Microsoft Excel"
return properties of active sheet of active workbook
end tell
You can access any of those properties just by asking for it. Good luck.

How to insert an excel chart into Word using AddOLEObject

I'm trying to create a linked OLE Object in a Word document using VB.Net.
Existing code uses InlineShapes.AddOLEObject(FileName:="abc.xlsx", LinkToFile:=True, Range:=Some Word Range) to insert a worksheet into a Word document.
I need more control than this. To select a range of cells I've found that extra information after the filename can be useful, for example: FileName:="abc.xlsx!sheet1!R1C1:R20C5"
Is there a way to specify a specific chart within a worksheet? So can I specify the second chart on the worksheet as the object to link to?
Thanks.
Thanks for your help Mark.
I eventually figured out that if the Chart is in it's own sheet, rather than an object in Sheet1, then the AddOLEObject code works correctly with the following setting:
FileName:="abc.xlsx!Chart1"
I'm happy with this solution.
A chart will either be a whole worksheet so address as per your sheet1 e.g. abc.xlsx!sheet1 or an object on a sheet so use the object name e.g. abc.xlsx!sheet1!chart_object

Resources