Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 204
Default Error Handling - Check a file isn't already open before overwritin

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Error Handling - Check a file isn't already open before overwritin

Check out
http://support.microsoft.com/default.aspx?kbid=138621

If this post helps click Yes
---------------
Jacob Skaria


"NDBC" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 204
Default Error Handling - Check a file isn't already open before overwr

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.

"Jacob Skaria" wrote:

Check out
http://support.microsoft.com/default.aspx?kbid=138621

If this post helps click Yes
---------------
Jacob Skaria


"NDBC" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Error Handling - Check a file isn't already open before overwr

On Error Goto linenumber
is used handle the error and go to a particular line..0 would mean not to
resume next or goto any other line but to the same line and return the
error...

You may go through the documentation
http://msdn.microsoft.com/en-us/libr...73(VS.60).aspx

If this post helps click Yes
---------------
Jacob Skaria


"NDBC" wrote:

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.

"Jacob Skaria" wrote:

Check out
http://support.microsoft.com/default.aspx?kbid=138621

If this post helps click Yes
---------------
Jacob Skaria


"NDBC" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 204
Default Error Handling - Check a file isn't already open before overwr

Thanks again. That link is an excellent resource.


"Jacob Skaria" wrote:

On Error Goto linenumber
is used handle the error and go to a particular line..0 would mean not to
resume next or goto any other line but to the same line and return the
error...

You may go through the documentation
http://msdn.microsoft.com/en-us/libr...73(VS.60).aspx

If this post helps click Yes
---------------
Jacob Skaria


"NDBC" wrote:

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.

"Jacob Skaria" wrote:

Check out
http://support.microsoft.com/default.aspx?kbid=138621

If this post helps click Yes
---------------
Jacob Skaria


"NDBC" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check for Open File! Ayo Excel Discussion (Misc queries) 2 August 11th 08 06:55 PM
Error Handling Kevin Excel Discussion (Misc queries) 4 June 19th 08 12:31 AM
EXCEL:Can't open any file without error saying it's ALREADY open??? Crackles McFarly Excel Worksheet Functions 1 November 1st 07 02:22 AM
check if file is already open mohavv Excel Discussion (Misc queries) 1 October 15th 07 12:08 AM
Handling #NUM! error Michel Khennafi Excel Worksheet Functions 1 February 26th 07 08:49 PM


All times are GMT +1. The time now is 04:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"