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()).
Related
tl;dr: Is there a way to have multiple (10+) excel Macro workbooks run the same project from a single location so that if I need to fix a bug, I don't need to fix it in every single workbook?
Long version:
My company uses excel workbooks for engineering charts. Any changes are formatted as bold and highlighted gray. We then have a revision "table" at the bottom (I say "table" because it's just some merged cells - there doesn't seem to be a way to make a separate table that doesn't follow the column sizing for the rest of the workbook, but that's a question for another day).
When we do a new revision, we have to first clear any formatting from the previous revision, make our changes (and format them), then insert a row to the revision "table", then unformat the previous revision entry and reformat our new revision entry. Then, we export the workbook as a PDF which we name according to our print naming format. However, it is easy to make mistakes when doing this because the file name must be manually entered according to the format.
To make this process less tedious/error-prone, I wrote a VB macro program to automate the above steps, among other things. It works great, and will be implemented on our charts company wide.
However, I can only do so much testing on my own - there are bound to be things I missed or can do more efficiently (I'm an engineer, not a professional programmer). And we have dozens of engineering chart spreadsheets. If we implement this and then I discover I need to fix a bug or make an improvement to part of the program, I don't want to have to fix it in every single workbook - that would take way too long and be too easy to miss a workbook!
Any advice would be appreciated.
I have to move a large amount of data from workbook A to workbook B in excel - workbook A has a different organizational structure than workbook B, and I want to automate A to transfer to B and organize itself into B's structure. I'm just getting acquainted with VBA, but before potentially wasting a lot of time - is this something VBA can do?
Definitely, as long as you have a reliable set of steps for translating the information from one format to another. If that's the case, then they can be codified and implemented in VBA.
If you're just getting acquainted with VBA, do some cost-benefit analysis. Sometimes it's faster to do it by hand. That being said, it will be very satisfying if you can get it to work. Nothing like going on a coffee break while your work does itself.
It now seems necessary to take my 50MB workbook and split it into 3 separate workbooks. Ultimately, when this program is moved to different computers, these 3 files will need to be moved together in order to function (of course). Is there a way for all of the links and conditional formatting to remain absolute? That is, all the files will be in the same folder, so a path would not be needed or wanted, just the workbook name and the sheet/cell reference.
If this is not possible or practical, am I missing something? Is there another way to do what I want to do, which is allow a very large spreadsheet to run on less powerful machines?
As long as the files are in the same relative locations, the links should update automatically. As far as I know, for the files in the same folder, it's not an issue at all. The same with going down the folder path. Problems might start when going the other way, so I'd keep them in the same folder.
Conditional formatting might be an issue though, but you could try linking just the conditions to the workbook you're trying to format.
To speed up the spreadsheet you can try manual calculations. I don't know how your spreadsheet looks like or how slow are the machines you're talking about, but that helps in most cases
P.S. Sorry for an answer when it should really be a comment, but I don't have enough reputation yet to do so
(edited a day later - see end)
Not sure what's happening here but it's occurring in a few workbooks I'm working with. Over time additional "Phantom" worksheets (or workbooks) appear as shown in the picture. Sheet13, Sheet14, Sheet15 etc are Phantoms and I have no idea how to get rid of them.
What I've tried so far:
1) Searching Google/Stackoverflow no joy but could be a terminology problem
2) Created SUBS to loop through ALL worksheets and workbooks but the only things it finds are the single workbook and the legitimate worksheets.
3) Creating code within one of the phantoms, which is possible. I created a simple SUB on workbook open within Sheet13 to return the name of the sheet or workbook, but no matter what code is there I get
Run Time Error '429':
ActiveX component can't create object
4) Changing properties on the phantoms. The properties for each phantom exactly mirror each other and mirror ThisWorkbook. If I make a change to one, say KeepChangeHistory to False, this is mirrored in ALL phantoms and ThisWorkbook. If I make the change back to True in another phantom, again ALL phantoms and ThisWorkbook are updated.
5) Checked links (greyed out). Tried F5 -> special -> objects "No Objects found".
I've basically tried everything I can think of and searched the internet over the past week before posting this here, as a last resort.
Does anyone have ANY idea what could be causing this (I'm leaning towards some bad object handling somewhere), but also HOW to remove them completely so the only things listed are the actual, real, worksheets?
Thanks for reading.
edit
It affects more than just this workbook (it's happening in 3 different workbooks), it is also getting worse over time. I have saved archived versions of all workbooks. If I go back a month, there are 2 "phantoms", if I go back 2 weeks there are 8 "phantoms" and if I look at one from just last week there are 13 "phantoms". This is one of the reasons I'm assume some poor object handling, likely related to ThisWorkbook is going on. Anyway, I'm going to take Rory's advice and create a new Workbook with NO phantoms and try and figure it out from there. Just want to thank Rory and Mark for taking the time to respond with ideas, it is appreciated.
Well, I guess the simplest answers are the best. What I didn't mention in the question is that each workbook I've worked on that has this problem is uploaded to a 3rd party application, which is, in turn, sent to a second 3rd party application (bespoke apps written by others).
The second application creates 1 or 2 of these "phantoms". I choose to work slightly differently to other developers and I actually use the output from the second application to make changes/fixes, then format that workbook and reupload to application one.
Over time, more and more "phantoms" appear, 1 or 2 per run through this process.
In the end, absolutely nothing to do with Excel, poor code (at least mine!), badly handled objects or anything else.
Thanks again to Rory and Mark for attempting to help. Maybe next time I'll actually start with the mindset of "I'm sure this ISN'T my fault!" and go from there!
I had exactly the same problem. I was reaching the Sheet41111. I used the option Book Inspection in the Information Menu, then I selected remove hidden objects and it luckily worked.
See the image attached, my excel is in Spanish so maybe the option is not really called "Book inspection" in the English version.
Hope it is useful
Pd- Unhide the legitimate sheets because it will delete all hidden sheets. I suggest trying it in a copy of the book. enter image description here enter image description here
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