excel - Putting Labels and Error Handler in the right place -


i using error handler in vba , want use in error handler in code suggested many experts on here.

sub test()  =1 100  on error goto errhand: filename=dir() folder= workbooks.open(folder & filename)  label1: code    code  close file  errhand: application.getopenfilename() goto label1  next  end sub 

i finding difficulties in running code in normal way. try pen file , if fails, call error handler , throw prompt select file , close file , same thing next files. 1 difficulty facing opened file never closes. in advance.

in addition jeeped's excellent suggestion:

sub test()  on error goto errhand: =1 100   filename=dir()   set folder= workbooks.open(folder & filename)   'label1:   code      code    folder.close  'based on using 'folder', above next  exit sub 'if don't this, code execution go right error handler  errhand: if err.number = <something>   application.getopenfilename()   'goto label1   resume next 'this simpler version, , doesn't require label , goto               'skips line of code errored, continues next line elseif err.number = <something else>    '...    resume 'allows retry same statement after making changes endif  'next  end sub 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -