I am getting a 'Code execution has been interrupted' message on exit from excel intermittently of late. And its frequency is increasing. End allows me to leave excel, but once I get the message, my machine must be rebooted to allow for excel to open and run macros again. This intermittent message does come up with basic excel usage at exit, and is not limited to excel sessions following VBA macros use. Has anyone seen this or have a solution. It is getting very annoying.
I have came across this issue few times during the development of one complex Excel VBA app. Sometimes Excel started to break VBA object quite randomly. And the only remedy was to reboot machine. After reboot, Excel usually started to act normally.
Soon I have found out that solution to this issue is to hit CTRL+Break once when macro is NOT running. Maybe this can help to you too.
Related
I have written a fairly complex application that uses Excel (2016) as front-end application for data stored in a MS Access database, using the ADO 6.1 library. I have noticed during macro code execution that SQL transactions triggered by my Excel application can take quite long to complete, and often the execution of the next line of code in my Excel macro depends on this SQL transaction first being completed. Unfortunately, macro code execution and SQL transactions are asynchronous operations, which means that the macro jumps to the next line of code even though the SQL transaction hasn't been completed.
My current work-around is to use a Sleep() function using the Windows API to insert a fixed delay, but this is a really ugly solution as it does reduce the performance of my application and depends very much on the CPU load, so it may sometimes work, sometimes not.
I haven't been able to find so far a solution to this problem, I can't find any hints on the Internet either.
Using Application.CalculateUntilAsyncQueriesDone doesn't help here either.
Does anyone have an idea or a hint how to halt macro code execution in Excel until an SQL transaction has been completed? Is there a method in ADO to check the completion of an SQL transaction?
Is your query within the Data/connections section?
I had this problem to, I turned off "Enable Background refresh" and added "DoEvents" to the VBA, this forces the data connection to refresh before it allows the code to continue. Downside to this is it makes excel feel like its locked up, But this resolved my issue.
Sub Button1_Click()
ActiveWorkbook.Connections("ScrapData").Refresh
DoEvents
....Other code....
End With
I have a relatively large (7MB) but more importantly formula and macro heavy excel file that I have been developing recently.
For the end user it must be able to be used in Automatic Calculation mode.
While calculating the whole sheet in Manual Calculation mode using F9 (Calculate Now) will work and calculate in ~10 seconds, but when I turn it onto Automatic mode, it will calculate repeatedly (i.e reaches 100% and then immediately starts again from 0%) and so freezes indefinitely.
So far I have tried:
Putting break points in all the VBA macros to see if it is hanging inside a macro
Removing all of the macros from the file (I was worried one of them was being triggered to run repeatedly in automatic mode)
but neither has worked leading me to wonder if the issue is not in fact VBA related.
Does anyone have any ideas about:
What might be causing this?
How I might diagnose the cause?
Happy to give more context if helpful. I am a relatively experienced excel user, and while generally don't write VBA macros from scratch am pretty confident at re-purposing code I inherit / find online. I am using a relatively powerful 6 core machine, but have tested it on others to the same results.
The issue turned out to be a volatile action that a macro was triggering. I had a macro that looped through hiding empty rows, but hiding a row is volatile, so then triggers a new calculation before the next run through the loop. The loop itself was 500 iterations, so that meant 500 sets of 3 second calculations!
See this link for more on volatile actions:
https://msdn.microsoft.com/en-us/library/bb687891(v=office.15).aspx
I have a problem with the Excel macro I created. The macro is quite complicated (7 modules with ~2500 lines of code) and it's used to automatically assign pallets to trucks and sort them properly. It works perfectly for 99% cases but when recently it had to assign more than 1200 pallets for one direction it stopped working.
The weird thing is that normally it can process way more than that but only if it is splitting for different directions. Also it crashes not in one place but sometimes when building pallet number 1108 sometimes 1110 etc. Between 1108 and 1111.
Also the crashing is quite weird. Before I turned on the "Break on all errors" It was just exiting the Sub that it was at that time working on, going back to the first one and then processing the rest of the code without executing it (ignoring every variable changes, every If etc.) The only line that was working was the Message Box. Also Excel was unresponsive afterwards.
I am declaring every variable, I have Option Explicit on top of every module I am using few Public variables and a lot of Local? (the ones that are across the Module not across the Project).
It is crashing mostly at this line:
w2.Cells(r, 4).delete Shift:=xlUp
where w2 is set as:
Set w2 = Workbooks(wb1).Worksheets("SDP Temp")
Have you ever encountered something like this?
0x80010108 RPC_E_DISCONNECTED The object invoked has disconnected from its clients.
Is what it means. COM uses RPC for out of process.
I managed to find a fix for the problem.
When the code was executing he was never truly exiting the SUBs until the directory was finished.
Because of that when there was more than 28 trucks it had around 50 subs opened in the background.
When I fixed the code so the subs were properly closed after they were used it started working properly.
I get the "out of memory" message when I execute my macro. It is too long to post but are there hints to better control the memory usage in Excel 2007? Getting rid of objects or something like this. I don't know how to do this.
best, U
Excel is notorious for this message and chances are, it has nothing to do with your computer's memory. I've had top of the line computers present this message with a 100kb excel program. The key COULD BE your userform and how certain parts get called. Best bet would be to run each event you have listed within your userform and see which one is the culprit.
Things to note:
Call
userform1.show vbmodeless
after all the textboxes, and other controls are set.
That sometimes works.
...Basically I have a lot of subroutines
to format and populate a worksheet
depending on criteria I define in a
userform.
I agree with #shahkalpesh comment. However, if you're looking for a strategy to help pinpoint the problem, you could try putting message boxes after you call each sub-routine from your main routine and observe excel's memory in the Task Manager.
Perhaps this will help you single out the offending code. Once found, you could post the code in here to resolve your issue.
I'd like to be able to schedule an Excel macro (VBA) to run in the middle of the night (after a file is ready) to create a customized workbook (multiple sheets, pivot tables, charts, filters, outlines, custom formatting, etc.). Currently, the macro is fired up manually the next day. Furthermore, it needs to run unattended on a server (laptop goes home at night!). Anybody successfully do something like this? Please, no Unix-side hacks (e.g., Perl modules) - need full access to VBA features, including database functions. Thanks!
Well you have some options.
First, for all Excel has to be installed on server.
Then you create a sheduled task to call a program.
In this case you can write e.g. a vbscript or .NET program to call the app, load the document and starts its content (your VBA). That should work at all.
Or you move the VBA code to a program and target Excel with your code, but prolly more work.
If you do this with .NET you have prolly best success. e.g. you can add an eventlog for successful run, etc.
If you can leave Excel running on the server all the time, you can use Application.OnTime to schedule the next runs of a particular macro (once it's run, reschedule another in the macro code). When I worked in banking we used this all the time to run night-time jobs.
If you cannot leave Excel running, I have to say you may be in a world of pain. It's possible to start Excel using an AT job (scheduled task) but you may have headaches getting it to run under the correct user privileges and if you use any addins you'll experience regular disasters where they failed to load and stopped Excel from starting up. At the end of the day, Excel isn't really meant to be run on servers (it's actually a violation of the terms of use) and starting/running/stopping it is not going to be a reliable system even if you do get it to work.