Run-time error '1004'

K

Ken Hudson

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
 
D

Dave Peterson

I'd guess that the file didn't exist.

Typing error in the folder/filename????
 
K

Ken Hudson

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.
 
D

Danny Boy via OfficeKB.com

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top