On Error Resume Next

  • Thread starter Thread starter Mike Archer
  • Start date Start date
M

Mike Archer

I want to switch backgrounds as an indication to the user
of unsaved changes. I want it to skip it if it is going
to cause a run time error so I use "on error resume next",
but it still errors when there is not enough memory. How
do I make it really skip the setbackgroundpicture function
if there is not enough memory?

On Error Resume Next
ThisWorkbook.Worksheets("Data").SetBackgroundPicture
ThisWorkbook.Path & _
Application.PathSeparator & "QPIBackground.jpg"

TIA
Mike
 
Application.MemoryFree returns the number of bytes available to Excel to use.
You need to determine how many bytes are required for your operation and
compare this to what is available and the abandon or execute your operation.
 
That sounds good. How do I determine how many bytes are
required for the operation?
Mike
 
I am not sure I know the answer or how it coould be determined. I would guess
as follows:

When the operation fails, Ctrl + Break and then query available memory. Now
you know how much is NOT enough. Let this be A. I would add something to
this, say 8K, and assume that the operation is not possible unless A bytes +
8K is available.

You'll need to fine tune this with trial and error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top