AndroidDev
AndroidDev

Reputation: 21237

Protecting a Chart Name

Does anyone know if there is a way to protect a chart name so that the user cannot change it? I've got quite a bit of code that references various charts. If a user was to change one or more of the chart names, things would get ugly in a hurry.

Upvotes: 1

Views: 104

Answers (2)

RHH1095
RHH1095

Reputation: 99

Try something like this code. Change "Sheet1" to "Chart#". Also the last little bit (commented out & Workbook.Sheets.Count) can be added back in to your coding to add a incremental naming if you have many charts as you noted.

    ThisWorkbook.VBProject.VBComponents(Sheets("Sheet2").CodeName).Name = "NewChartName" ' & Workbook.Sheets.Count

Upvotes: 0

Jook
Jook

Reputation: 4682

I might have a solution for you, but it brings some overhead.

You could add a real chart for every chart you are using and want to have name-protected in your workbook. They appear as seperate tabs (like a table) in your workbook.

Looks like here:

enter image description here

Right click on your chart and select move chart then new sheet. This way you are going to have "better" chart objects, which you can protect seperately through VBA or through Ribbon-Menue AND you have an internal CodeName!

Like here:

enter image description here

With an internal CodeName your user-troubles should be done with, because they can name them how they want and so can you ;) I don't trust indexes eighter and hate using user defined names - code names are the best, except for handling in code, but that is just a major vba flaw.

I'll guess, that those additional charts will however anoy you a bit, so just make them invisible and use copies of them as ChartObjects in your tables.

This should be it.

Further I stumbled uppon the interesting fact, that you really only can protect the chartname by protecting it as a nested object in a protected table. Even with my attempt users would be able to change the name, unless you protect the workbook-structure and all table/chart names with it.

Hope this helps ;)

Upvotes: 1

Related Questions