Run-time error '1004'

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm running Windows 2000 and Excel 2003.
When I run the code below, I get a "Run-time eorr '1004': Method 'Open' of
object 'Workbooks' failed" error.
Can someone tell me why?
TIA

Sub Macro()
Workbooks.Open Filename:= _
"C:\downloads\GPF_PY.xls"
End Sub
 
Thanks for the reply. This was really puzzling to me.
The initial file was saved as a CSV file and then opened in Excel and saved
as an Excel file. It did exist as an Excel file.
The problem was that, when it was saved as a CSV file, its worksheet brought
the default name ".csv)GENSOFMO(2)" with it. I saved the file in Excel with
that worksheet name. I can open the workbook "manually", but got the error
when trying to use VB.
I renamed the worksheet and life is good again.
 
Hi Ken

This script will allow you to select the file you wish to open, if the format
you want ins't csv then change it to desired format

Application.DisplayAlerts = False
Application.ScreenUpdating = False

fileToOpen = Application _
.GetOpenFilename("Comma Delimited (*.csv), *.csv")
If fileToOpen <> False Then
TextBox2.Value = "Opening " & fileToOpen
Else
Exit Sub
End If

Workbooks.OpenText Filename:="" & fileToOpen
DoEvents
 
Back
Top