Runtime Error: "Out of Memory" From Excel Macro
I have one macro, which is called when a cell change occurs. This macro selects images, deletes them, and inserts another image depending on a cell value using the following code. I have the same code for two sheets.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Shapes.SelectAll
Selection.Delete
'insert image code here.
End Sub
In one sheet, it's working perfect开发者_开发技巧ly fine and deletes all images, while in the other sheet, it gives me the runtime error "Out of Memory" and highlights the following line:
ActiveSheet.Shapes.SelectAll
Can anyone tell me why this is happening? It works perfectly fine in one and not in the other.
One other thing I want to tell you is it was working fine when I gave this Excel macro to my client; both sheets were working fine. Suddenly after 2 days, he started getting the error on one sheet on which he was working a lot.
I don't know why this is happening. Can anyone tell me what's the reason for this and how I can solve it?
Can you provide your insert image code? If you are changing the current selection yourself in that code, then this procedure would be called endlessly. You should consider disabling events while processing this event handler as per the following code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
' do something
Application.EnableEvents = True
End Sub
精彩评论