Use Excel when a macro is running - excel

I am not sure if this can be done, but it would be great if the user can use the excel spreadsheet while the macro is running at the backend. Is there any way this can be done? Thanks.
EDIT: The user is repeatedly (>10^5 times) generating Random permutations on n items (n ~ 100) through a macro. This might take around 10-15 mins (or more) to get done. So, if the user can open the excel workbook to do other tasks, while the macro is running , it would be nice. (It would typically be a different workbook from the one in which macro is running). Please let me know if this can be done and if yes, any performance effects that it might have on the macro which is running. Thanks.

The user can open a second instance of the Excel application while the macro is running and work as normal on other workbooks. The same workbook can also be opened but as read only.

Related

.xlsm files freezes over activating after long hrs of inactivity

Like suppose, your .xlsm file is about more than 5 mb
It has more than 20 sub procedures any many more. Many inbuilt formulas & functions are used in the background on the excel sheet. Yes, more than 20 Excel sheets. So this is how large Excel VBA Application looks like.
Now, I found one issue with the large application, It stops working or freezes or not respond when your application is open in your system for more than few hrs without having any action on it!
Yes, and as soon as you activate your workbook after a long hr of other work, workbook almost freezes or showing not responding. and we need to close the excel file anyhow for further any process.
It's very common encounters who has worked on large excel files. Please discuss here the reasons, causes, and solutions.

Excel 2010 VBA - Continually Looking In Folder for File to Process?

I have a need to build a macro in Excel 2010 that basically runs continually (started by button or stopped by button) that looks into a file folder. If a file is created there and named a certain way then the macro opens it and processes the data inside. The file is then closed and deleted. The macro then continues on to watch the file folder for more files to process
Is this a reasonable / doable macro that I could create in Excel with VBA? Can VBA continually run without issues?
Best Regards
Andy
Is your program continuously pulling changing data from the Excel sheet? If not, I would advise creating the program in another language and running in a continuous loop containing your code and the sleep() function. If so, then I would recommend using the worksheet change event, and you cannot edit the worksheet while a macro is running(even if you use the sleep/wait command in VBA)
This link might also prove helpful: How to get VBA Macro to run continuously in the background?
see this thread for some ideas:
https://superuser.com/questions/226828/how-to-monitor-a-folder-and-trigger-a-command-line-action-when-a-file-is-created
the first answer probably will do it, just trigger the excel macro you want from that. You can get as fancy as you want with the execution. The application.ontime function only works if excel is open, I believe.
What you want is to find a way to monitor the folder constantly.

VBA and Excel running in parallel

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?

Excel 2007 crashing when saving workbook after running macro

I am using Excel 2007 (32Bit) on a Windows 7 64Bit machine.
I have a large Workbook with 12 sheets and 18 VBA modules.
All of my subroutines run flawlessly but one is causing the following issue:
The macro itself runs from start to finish successfully just as specified. After running the macro successfully, the workbook crashes, when I try to save it. It also crashes when AutoSave tries to save the workbook. The workbook does not crash when I simply close it.
By crashing, I mean that I get the message "Microsoft Office Excel has stopped working".
In the Windows Event Viewer I have identified the error message 0xc0000005.
In the folder where the workbook is saved, I find the temporary files that Excel creates when saving a workbook (named something like 9BB7B000).
I have tried to repair Excel in the Programs and Features part of the Control Panel but it has not worked. Furthermore no Add-Ins are enabled.
I suspected that the code module of the problem-causing macro was too large (90KB) so I split it up into two modules smaller than 64KB. However, the problem remains.
I would appreciate any help on this issue. I would like to get around reconstructing the workbook manually, if possible, as that would mean an enormous effort.
Thank you very much in advance.
Jochen
I had the same issue some time ago and carried out a research to identify the issue to no avail.
I noticed that it worked fine on workstations with better procs and more ram.
However the only way for me to proceed was to create a new workbook a one-by-one copy each worksheet from the old workbook and see which one is causing the issue. If the macro is causing the error then try to add a "sleep" command between loops so that the Excel file regains control and can execute and awaiting events/commands.
The post was 9 months ago, could you fix it?
What does that specific macro do? Because there are several solutions to this problem.
It seems that a certain "action" in your macro takes too long.
You can search for that specific action and us application.wait to slow your macro down. If this doesn't work, you'll have to find a way to reduce the "workload". But to do that, i'll need to take a look at your code.
Turn off the AutoSave function in Excel Options

Excel VBA UDF Add-in function #Name error

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.

Resources