This is a question that I have always had but never really gave it much though.
What I have at the moment is a worksheet that displays data, and the user refreshes whenever needed. So:
User triggers a VBA Function
VBA Function gathers data and analyses WHILE USER WAITS
VBA Function dumps the result on the spreadsheet
User continues viewing data
Since the data analysis is all done internally in VBA (No use of workbook, only recordsets, arrays, library etc.) I wanted to somehow be able to allow the user to continue viewing the original data, while VBA works on getting and analyzing new data.
I know you cant use the workbook AND run VBA at the same time, but you can however, have two excel instances and work on one workbook while the other runs VBA.
So could I somehow have my original excel instance call another excel instance and have it run the VBA while I work on my first instance?
Any Ideas?
(Also, not sure if the tag "Multithreading" is technically correct)
First thing - there is no multithreading for VBA in Excel.
Second thing - since Excel 2007, Excel supports multithreaded recalculation of formulas.
Therefore to approach multithreading calculations in Excel you can do at least 2 things:
Create a second instance of Excel (new Application instance! Not a new workbook within the same Application!) and execute the macro remotely.
Create UDF functions (User Defined Functions) in VBA. Unfortunately you cannot edit other cells using UDF but you can save the results of your computations in a Global variable and then print the results.
My recommendation - go with option 2.
I haven't been able to try this, but it seems like you can launch Excel from VBA using Application.FollowHyperLink. The hyperlink would have to be the local path to the sheet. You might have to use VBA to also make a copy of the sheet first.
Have you thought through the concurrency issues with having two copies?
Related
I made some very complex Lambda formulas which I use frequently to validate UPC Check digits, and convert UPCs from UPC-E to UPC-A format
I tried to set them up as named ranges, then save the workbook as an Add-In, and followed all the steps I could find to add that add-in into my Excel, however it doesn't look like it keeps the named ranges at all (which is where Lambda formulas are stored)
Is there any way to get around this and still save these Lambda formulas as an Add-in?
I really don't want to have to re-create the entire complex formula in a module, but it seems I may have to do that in order to have the formulas available in every workbook I open
Alternatively, if there's any way within a VBA function for me to use my existing Lambda formula, I would love that, but I'm not sure if that is possible as I know that VBA is a quite different language than Excel's formulas.
I considered making a macro which instead would just add those named ranges to my workbook, but hoping for an easier solution.
Please let me know if you have any tips for this!
What about maintaining a Template,that’s what I do, means they are there in your new books and a quick way to access them for manual copying across to existing workbooks.
2nd idea is use autocorrect to store them with a shortcut word. Autocorrect is application level and there is VBA you can find to copy your AC shortcuts to a backup workbook and reimport them if your PC crashes.
my question is a pre-code question, as I would like to verify if and which is the best option to go about this - either formula, VBA or not possible.
I have a main workbook with an array of codes inside cells in sheet 1 - all in the format HXXX-XXX-XXX where X is numbers ranging from 0-9. Each code has an associated revision number as shown in the attached picture.
The workbook itself is named in the format: 'HXXX-XXX-XXX-YY Example Title' where YY can be any number starting from 0 to infinity (in theory). Only YY is subject to updates in the title. If changes are made in this workbook, then a new version is saved, with the YY changing in the title to the next consecutive number - Nothing else changes.
From this main workbook there are a large number of other workbooks (around 50) which share the same codes and revisions. My goal is to link all these workbooks up so that I only have to update a core main workbook and the rest of the codes (HXXX-XXX-XXX) revisions in all the other linked workbooks update accordingly.
The problem is that the other linked workbooks have a dynamic name in the format: 'HXXX-XXX-XXX-YY Example Title 2' where YY can be any number starting from 0 to infinity. YY gets updated to the next consecutive number if a change is made inside the document and this document is then saved as a separate document using Save As. NOTE: not all workbooks will get updated at the same time, as it all depends on which codes and therefore revisions are changing.
My question is firstly, is this possible with current excel functions to update links with ever-changing workbook links, which are saved as different files each time in the same folder?
Secondly, I have read about the INDIRECT function, but it is limited only to having the required workbooks opened at the same time as the updates to the main workbook, hence I am unsure that Formulas will work (I will be linking 50 workbooks to the main workbook) - From this I am gauging that VBA may be the best option, but I would like to double check this is possible before I begin attempting the code.
Of course the use of Formulas in the sheets would be much better, but because the file names are dynamic, and since the updated workbooks are saved as different files each time changes are made to it, I don't believe this is possible.
If I understand your problem correctly you need to differentiate between 3 things.
Using only Excel Formulas.
The problem with this is that formulas crossing workbooks have the big disadvantage, that you need to have the source-workbook open, otherwise manny formulas will not work correctly or update. You also have the disadvantage that saving the file needs still to be done automatically. The advantage is that you do not need VBA macros.
Using Power Query
With Power Query youmight be able to solve the problems with the dynamic names.You can even read a whole folder of files, combine them and do transformations without the need to open the files manually. But you still need to save new files manually and the files will only update once they are opened.
Using VBA
You can prettymuch do everything you asked in your problem description but VBA has its own disadvantages. Firstly the file-format ".xlsm" is not allowed by the IT department everywhere. Also to work, every user using the files needs to activate macros, otherwise the macros won't get executed. Therefore I think a VBA solution is better fitted if you only have a small circle of users or if you can execute the macros on your own (e.g. if the main workbook was updated, you need to execute a macro which opens, modifies and saves all affected files). After that you colleagues do not need VBA themself.
Possible solution:
To avoid VBA you could try to create a Power Query in each "other workbook". The query will read all filenames in the folder where the main workbook is located. Now you sort and filter for the workbook with the newest/highest ID/Titel automatically and load the result as an seperate Excel sheet (all that is possible with power query and without VBA).
Now you can use the "indirect" formula to use the ID/Titel to link to the newest main workbook. As mentioned above this will require that the main workbook is opened. Otherwise the indirect formula will not update the values. If that is out of the question, you probably need to go with VBA.
I am trying to debug a workbook that has external add-ins and crashes unexpectedly without warning (window just disappears and process dies). Is there any way that I can log the functions calls that excels is doing on calculations so that I can see the last excel (or VBA) function that got called before the crash??
I don't think there is a direct way of accessing the dynamic calculation chain.
I would try switching to Manual Calc mode and re-calculating each worksheet in turn (Shift-F9 to recalc the active sheet) to see if you can isolate the problem to a worksheet.
The use Range.Calculate (you can download my RangeCalc addin from http://www.decisionmodels.com/downloads.htm to try to isolate to a block of cells and then a formula.
Currently we have a Excel VBA application, which consists of 25-30 Excel sheet (and all of those sheets all hidden and we do background processing on them and display it to VBA forms UI), and we have developed a UI using VB forms. But problem we are facing is whenever we click on Save button using this code:
ThisWorkbook.Save
But this saves entire workbook not an individual sheet, so even if we make changes in single sheet it saves entire workbook and this save processing makes very slow (since it needs to save all excel sheet containing lot of data unnecessary, even if there is no changes).
My question is is there any way we can save "only one sheet in a particular excel sheet" not an entire excel file?
Note: I am a Java developer and I worked on VBA before, But it was years back, and I have forgotten bit. Any guidance would be appreciated. Or any pointers on how to handle this situation would be appreciated. Please let me know if you need any more information, I can edit this question.
What I have tried already? I did a lot of research from yesterday, I searched in previous questions on SO, but didn't get any useful information. As per my research it says we cannot do this. Am I on right path?
The short answer is no. You cannot save a single worksheet at a time.
You may want to try to reduce the amount of data in the workbook. Try storing data in several workbooks and when it is needed, open that specific workbook, make the needed changes, and then close it.
If it is necessary to have access to all data at once then consider using access or some other database.
It is also possible that the sheets have "blank data". Cells that don't contain anything in them but excel thinks they do so when saving it tries to save way more than needed.
Assuming that it is the active worksheet that you want to save then you could do something like this:
ActiveSheet.Copy
ActiveWorkbook.Close True, "path"
This copies the active worksheet which creates a new workbook which will become the active workbook. Then just call the close method on that and give it a file name.
I think you should consider splitting your application into multiple workbooks:
The workbook that contains all the logic, user forms and programming code. This workbook handles all other workbooks as well as the displaying of it. Potentially, this could be even an "Application Specific Addin", that stays dormant but activates as soon as any of it's subsequent workbooks gets opened. For this architecture approach check out the section on "Application Specific Addins" in this link.
This workobook/add-in can also hide the other workbooks, so that the user will not notice it's multiple workbooks.
One or multiple data workbooks: Depending how interlinked the data is, you can separate this, e.g. in a "Sales data" workbook which contains the large database, as "Base data" workbook, that contains all the smaller data (e.g. products or stores tables).
This way, you can reduce the saving to the "relevant" sheets. However, of course this requires quite a bit of reprogramming - but it's worth the effort, as for instance it also allows to provide updates/bug fixes without having the transfer the data between versions, as you only need to distribute the the file with programming logic. :-)
I have a UDF I wrote and put in an add-in. I put it there (with a library of others) so that I can change functions and just deploy an updated add-in, thereby eliminating the need to modify hundreds of workbooks which invoke the subs/functions should I need to change them. This is all being done in Office 2007.
It had worked well until recently when users started moving to Windows 7. Now, only on Windows 7 (XP is still okay) there are #Name errors in cells. This occurs under specific conditions (only a problem for Scenario D below). In short, I have two workbooks each invoking, let’s call it, “FunctionX”, so let’s say cell A1 of each has “=FunctionX(parmA, parmB)”:
Scenairo A – If I open either workbook separately (All is well)
Scenario B—I open both workbooks at the same time (All is well)
Scenario C—I open both workbooks separately, one after the other, in different instances (All is well)
Scenario D—I open one workbook, then the second, in the same instance of excel (#Name errors in cells of first workbook invoking FunctionX)
I realize the work-around is to only operate via Scenarios A-C, however I keep getting users complaining about D. If they go into any invocation of FunctionX on the #Name offending cells and hit enter, the #Names go away, but a programmatic forced recalculate does not do this (my initial attempt at a band-aid). Is my only recourse to write a procedure that loops through all open workbooks, goes into a cell with my function forcing a code-driven enactment of what the user is doing, or am I missing something?
Thanks…any/all advice appreciated.