Error Handling - Check a file isn't already open before overwritin

N

NDBC

I have some code that exports data from my workbook to a new workbook. The
file name is the strFile variable and the file folder path is the strFolder
variable.

wbNew.SaveAs strFolder & strFile & ".xls"
wbNew.Close

I get an error if you are exporting data for a second time and have
forgotten to close down the exported file after viewing it.

Can I put in some sort of check that will show a message saying the file is
open, please close it and try again rather than it taking the user to the
debugger.

Thanks
 
N

NDBC

Thanks Jacob. Took me a little while to sort out what a function was and how
they worked but I'm there now. One thing I don't understand is this statement

On Error GoTo 0 ' Turn error checking back on.

I know it says it turns error checking back on but what does goto 0 mean.

On another sidenote. In the process of putting explanations through my code
I realised that I was doing a few things the long winded way and have now
made things more efficient. Another benefit of going through the process.

Thanks for all your help.
 

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

Top