Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default Error Handling works only once

I have these codes below. The Error Handling works only for the first file in
the folder but not the other files. Does anyone know why? All the files in
the folder do not have Sheet ABC. Thanks in advance for your help.

For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open FileName:=file.Path, UpdateLinks:=xlUpdateLinksNever
On Error GoTo ErrHandler
Sheets("ABC").Select
ErrHandler:
ActiveWorkbook.Close SaveChanges:=True
End If
Next file


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9,101
Default Error Handling works only once

Try handling error like this. If an error occurs when the select command is
executed it will close tthe workbook, otherwise it will go to On Error
statement and return to normal error handling.

For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open FileName:=file.Path, UpdateLinks:=xlUpdateLinksNever
On Error Resume Next

Sheets("ABC").Select
ActiveWorkbook.Close SaveChanges:=True
On Error GoTo 0
End If
Next file

"linglc" wrote:

I have these codes below. The Error Handling works only for the first file in
the folder but not the other files. Does anyone know why? All the files in
the folder do not have Sheet ABC. Thanks in advance for your help.

For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open FileName:=file.Path, UpdateLinks:=xlUpdateLinksNever
On Error GoTo ErrHandler
Sheets("ABC").Select
ErrHandler:
ActiveWorkbook.Close SaveChanges:=True
End If
Next file


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
Handling #NUM! error Michel Khennafi Excel Worksheet Functions 1 February 26th 07 08:49 PM
Error handling in macro michaelberrier Excel Discussion (Misc queries) 7 May 23rd 06 09:33 PM
Error handling in a search michaelberrier Excel Discussion (Misc queries) 2 May 21st 06 07:08 PM
Error handling in this code L. Howard Kittle Excel Discussion (Misc queries) 4 October 8th 05 12:35 PM
Error Handling for "my" menu bar dstiefe Excel Discussion (Misc queries) 0 July 27th 05 10:52 PM


All times are GMT +1. The time now is 09:37 AM.

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"