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.
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:
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:
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 ;)
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
Related
I've found several sources that appear to give me a solution to my need, but each one has come up short. I think my solution is in using VBA UNION; however, I am a complete VBA noob, so I feel like I shooting in the dark. Here is my need.
I have a worksheet with multiple tabs.
Each tab has the same headers for the first 10 columns.
I'd like a sheet that is a summary of the first 10 columns of all other sheets combined.
I thought if I made each sheet a table and named each, I could create a range of ranges and then just call that combined range on the summary tab. My thought is there a solution somewhere with Union here, but I don't know enough to know if that's right or not.
I need basically what this solution is, but rather than it running on a run command and doing a copy/paste, the result just needs to dynamically update. https://danwagner.co/how-to-combine-data-from-multiple-sheets-into-a-single-sheet/
As a Google Sheets user, this is super simple, but I have to use Excel for this. I feel like there must be a simple solution that I am just completely missing. In Sheets I'd have just done ={range1;range2;range3;etc} and I'd have had my output, if that helps someone get what I need.
Any help here is very much appreciated.
Part of what is great about VBA is that it is an event-driven language, so you can set your code to run every time a cell is changed, workbook is saved, etc. instead of having to press a button. I recommend reading up to section 3.1 of Excel VBA Events - An Easy Guide where it explains how you can use:
Private Sub Worksheet_Change(ByVal Target as Range)
CombineDataFromAllSheets
End Sub
seeing the way my current question trends I don't think this one will earn a lot of merit points. admittedly, this is a "I'm lazy of doing repetitive tasks and want to automate it" kinda question
Question: is there a way to dynamically have the pivot update its target range to the active worksheet and not the last sheet you copied it from?
my goal is to get something like
=activesheet!$a$1:$b:$2
why I'm asking this question: I never really liked pivot tables, always thought they were a waste of time, but since my boss likes them and doesn't like vba, I gotta conform and use the dumb pivots.
really not sure what kind of other materials or proof of research you guys want with this question, but i did try to search on my own and found nothing. if theres anything else you guys want just ask. Thx
Can't comment, so please don't complain for putting it in here ;-)
There is something which could ease the pain when updating the data source after pasting the pivot table into a new workbook:
If the Pivot Table does not refer to a range but to an Excel table instead (cf. Ribbon -> Insert-Tab -> Table), then you will just need to remove the file name in the data source without updating the range (because there is no range, just the table name)
I thought this should work, but at times Excel has a tendency to make simple things complicated (or impossible).
I'm setting up a bunch of graphs. Because I anticipate I will have to translate labels at some point, I want to use named ranges for all my labels (then'll offset it for translation). There's VBA involved for other stuff already, so I kinda like to use name manager as much as possible. I think it makes things easier to maintain as well.
The problem arises when I try to set the Axis Titles, and the chart Title, as a reference to a cell that is a named range. I know I can set the reference to a CELL, by doing so entering in the formula bar while having the title selected something like:
=worksheetname!$A$1
However, let's say that my that cell is named graphlabel_waterpointY. I would like to do something like:
=graphlabel_waterpointY
Which fails. Upon diggin a bit, I found that I need to put the workbook's name before I can use the named range as such, like so:
=WORKBOOKNAME.XLSM!graphlabel_waterpointY
That works, however, I don't want the user to rename the workbook and later find that all the graphs titles show !VALUE instead of proper titles. Therefore I want some sort of flexible reference for the name of the workbook as well. I don't want to use:
=CELL("filename",A1)
& isolate the string there, because if the user has another workbook open that can fail as well. So I thought "well, since I'm already using VBA, I'll just set the workbook name in a cell upon workbook opening & have my formula for the titles reference it".
However, that fails as well. Even something like:
=META!$A$1!graphlabel_waterpointY
(assuming META!$A$1 contains the workbookname) will fail as well.
It seems dumb to me that I would have to hard-code the values. I'm aiming to have something translatable later on. Of course one can just do different version, but then it sucks to have to maintain 2 workbooks. Or I could settle for hard-coding the workbook names & have it said they can't change it. But that sucks as well.
==================
My solution as this point is the first mentioned, e.g. even if the cell has a named range, refer to it by its A1-style reference. Works but then I lose flexibility in the layout..... Maybe I'm being picky....
Everyone !
it is my first post here and as a novice I hope my question will make sense.
I'm a french intern working for a large firm and was assigned to the making of an "automated report" (I know, another one...).
The situation is pretty messy, each department generate reports for themselves with little to no constraints concerning the name, layout, size and data contained inside. (meaning that from one month to the other, each department may add or suppress an indicator, change the disposition of the data etc.)
I work for the performance and strategical division and need to create a four-table Excel file which would ideally be able to get the relevant data from the different files issued monthly. I cannot change the way files are updated on the intranet and my boss is clearly illiterate when it comes to computing.
Is it even possible for me (I do not know how to use VBA yet but I am a fast learner) to do this, while being transparent to her (zero or really easy manipulations), and adapting to the changing data-files format ?
Thank you in advance for any answer and sorry if i am not explaining myself properly.
I wish you all a great day !
Jules
In which formats would all the arbitrary files be?
In VBA you can open quite many file types and read the data if you just know the format and how data is organized.
If those files are in Excel files too, you can use Workbook.Open;
Dim wbReport As Workbook
Set wbReport = Workbooks.Open("ArbitraryDirectory\\ArbitraryfileName.xlsx")
Then use that workbook just like your main workbook;
OneOfYourFourTables.Cells([Row], [Column]) = _
wbReport.Sheets("TheArbitrarySheet").Cells([Row], [Column])
Or use Range objects and/or Copy methods. (I generally like to loop around the Cells()).
I have a excel file that I need to give to a client. It currently comprises of one worksheet but could easily have many more. On the sheet there is a graph and a selection of slicers.
The problem I have is that if I hand this over to the client, they'll see the underlying code and possibly not need our services going forward.
How do I protect the sheet/file and only allow them to view data and operate the slices without seeing any of the background workings?
They must not be able to save a copy, access the SQL code or save changes.
Thanks,
JJ
You can bolt down excel with the protection options so that people can't edit objects and can only select non-locked items. You can also password protect vba and force read-only open of the spreadsheet.
http://office.microsoft.com/en-gb/excel-help/password-protect-worksheet-or-workbook-elements-HP010078580.aspx
There are lots of protection options available but the best thing you can do is reference a report/webpage with the data on instead of doing a direct db connection. This will alleviate a lot of security risks whilst also blackboxing your database.
IMHO
Only lock your spreadsheet down enough to prevent silly mistakes - combined with your data being a blackbox, they will get a usable spreadsheet and be much happier with you than if they felt you were aggresively trying to withold stuff from them. They may run off with your spreadsheet but the extension of trust to them will help discourage the behaviour and at the end of the day, if someone wants to really harvest your IP, they will do so no matter how many controls you have in place.
you also can try to protect VBAProject at the VBA window, something like this:
and put a password
this way the user can manipulate the worksheet without seeing your code, additional to this, block your worksheet like #StephLocke saids.
Your Workbooks can always be vulnerable, but you can lessen the risk to corrupt your code.
PS. My Excel is Spanish but the options are at the same place.
It is possible to protect the worksheets and still allow to interact with the slicers (and only the slicers).
Set each slicer's properties to not "Locked" by right clicking the slicer and selecting "Size and Properties..." and unsetting the "Locked" property.
Protect all other worksheet elements including cells and Pivot Charts in a similar fashion (set their "Locked" property).
Finally, protect the worksheet via “Review” -> “Protect Sheet” and select "Use AutoFilter" as the only action in the selection "allow for all users of this worksheet to".
You might also confer to this answer.