View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Anolan Anolan is offline
external usenet poster
 
Posts: 11
Default Error opening files from a list in a spreadsheet

Help! I get Run-time error 1004 when I run the following macro. I have a
list of file names (ex: 1025104902.xls) in my personal.xls that is defined
by a range, say "GA". Sometimes an Excel file does not exist for a file name
in this list. In this case, I want the macro to bypass the file not found
error and resume the routine with the next file name in the list. Can anyone
please help me with the code that will do this? Thank you. Andy

Here is part of my code from it starts to where it stops:

Private Sub CommandButton1_Click()
' Report CC EV 100
' Format_100_Rpt Macro
' Macro recorded 11/8/2005 by anolasco
'
'
Dim myCell
Dim myRange
Dim myDir As String
Dim myDate As String
Dim myHeader As String
myRange = Application.InputBox(prompt:="Enter a Range", Type:=8)
myDir = Application.InputBox(prompt:="Enter File Location",
Default:="U:\CC_EV_100 Reports\mmyy\", Type:=2)
myDate = Application.InputBox(prompt:="Enter Date and Time",
Default:="mm/dd/yy hh:mm am", Type:=2)
myHeader = Application.InputBox(prompt:="Enter As of Date",
Default:="October 31, 2005", Type:=2)
Windows("PERSONAL.XLS").Visible = True
Workbooks("PERSONAL.XLS").Activate
Sheets("Sheet1").Select
For Each myCell In myRange
Workbooks.Open Filename:=myDir & myCell (run-time error 1004)
(In between I have code that does formatting and calcuations.)
Next myCell