If an Excel Workbook has many sheets and some of them have macros inside, the only way I have found to determine which sheets have macro is by clicking each of them in Project Explorer (Ctrl+R in VBA).
Is there any other way to do this?
I answered a question recently in MSDN and ultimately wrote a blog post on it.
Topic: Check if an Excel File has a Macro
Link: http://www.siddharthrout.com/2012/04/12/check-if-an-excel-file-has-a-macro/
You can then use .VBComponents.Item(i).Name with .VBComponents.Item(i).Type to check which "Sheets" have "macros".
EDIT
Technically speaking every macro is a piece of code but it's not necessary that every piece of code is a macro. So if you are just checking for macros then see the 1st part of the blog post and if you are checking for any code then look at the 2nd part of the blog post.
You can loop over the sheets and use the following syntax:
If ActiveWorkbook.VBProject.VBComponents(sheetName).CodeModule.CountOfLines <> 0 Then
sheetName being the name of the sheet.
For more advanced use, you should check this page which gives more advanced examples.
Related
Sorry to bother you, i would like to stop people from being able to write code on VBA on my excel sheet.
But I can't do it since there is no VBA code already in place.
Then you will tell me to put some useless VBA code and protect it, but i can't do it because of workplace regulations (The document is approved as an excel sheet without vba).
So what do you think are my options ?
Is there a way to stop users from writing VBA code if you have no VBA code already written ?
If i use the project properties to add a password it won't work (because no vba code is written). I have tried this several times already
Thanks a lot,
Have a great day
I have written a code that should run when a cell in the worksheet changes. It works well and fast.
Now I want to add another case to the code... but now I can´t find it.
Can I somehow search for the code? There are no modules or forms and I have tried to select worksheet and change.. but the code does not appear.
Please help
Regards
Henrik
If the code reacts on Worksheet change, it's within Microsoft Excel Objects for the sheet
I don't know if this will help, but when my code hides (hugely frustrating!), I hit the "Macros" button - it should show up in the list there if it's working in your sheet. Then you can select it, choose "step into", and at least get to where you can edit the code. Good luck!
For example, I have two worksheets in my workbook. One workbook is for data only, it has 10 columns but the number of rows can increase or decrease.
I'm able to use the paste link special function on worksheet two, to link to the current data but is there a way that I can automatically update the link so that if I add additional rows on the Data worksheet that those will also appear on the other spreadsheet?
I'm hoping I'm clear on this.
Thank you for your help.
Jim
As #jeffreyweir stated, you do need to use code for this. In this case, I used ODE in C# .net after searching stackoverflow for examples.
Jim
I need to some help.
I found a page from a book and I wonder how to create this solution from the beginning to the end?
Here's your help:
Read the first several chapters of your book on how Excel works.
Start the Excel Macro Recorder
Execute the items in Step 6 of your book
Stop the Excel Macro Recorder
Look at the code Excel generated for you
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to refresh/load RTD Bloomberg function (BDH) in excel in vba
I am working on an Excel Spreadsheet with VBA. I have a Bloomberg BDH function that I want to refresh from VBA. I tried recording a macro and clicking the Bloomberg->Refresh Workbooks button but the macro came up empty. How can I do this from code? I'm using Excel 2007 and I found one option of entering
Application.Run "blpmain.xla!RefreshAllStaticData"
but blpmain.xla can't be found. I'm not sure what version of Excel/BBG-Addin this was for.
Any help?
What I ended up doing was re-pasting down the bloomberg formulas in the appropriate ranges. This forced the data to redownload. Not the most ideal solution but it works.
Basically, unlike BDP...BDH doesn't refresh because its historical(H), if you want refresh it you need to resubmit your formula.
Maybe not the most elegant solution but what I do is change something in the BDH formula. So you can click on a button you make that takes the data and adds a day and then removes it back. That slight change causes it to refresh.
Another thing I used to do was have a BDH bring in all the historical data, but have the top column a BDP realtime feed so it kept freshing.
In the end, the easiest way is to have the users close the excel sheet at the end of the day and have them reopen it when they need it.
Are you sure you've set a reference to the addin?
Open a code module in the workbook in which you want to use the
Add-In's functions
Go to Tools > References to open the References dialog where you
will see a list of all the libraries and other objects (like
Add-Ins) to which you can set a reference.
Put a tick in the box next to the name and click the OK button.
Source
Once you've done this, you can refer directly to the xla function RefreshAllStaticData.