PDA

View Full Version : Error 424: what am I missing?



kualjo
07-31-2014, 09:01 AM
I have the following code that allows me to select a file. Once I have selected it, however, and click Open, I get Run-time Error 424 (Object required).

...
1 Dim csv_file As Excel.Workbook
2 Dim prq_file As Excel.Workbook
3
4 Set prq_file = ActiveWorkbook
5
6 Set csv_file = Application.GetOpenFilename("All files, *.csv")
7 If csv_file = False Then
8 Exit Sub
9 End If
...

I then tried changing line 6 to a With block, but then got a 91 error.

...
6 With Application
7 csv_file = .GetOpenFilename("All files, *.csv")
8 End With
...

Can someone please tell me what I'm missing? How can I rewrite this to get the file to open upon selection? Thank you.

Bob Phillips
07-31-2014, 09:45 AM
Works fine for me without the set and with or without With.

kualjo
07-31-2014, 10:02 AM
Thanks xld. Is there any reason why your code worked and mine didn't if they are the same? What might cause that discrepancy?

kualjo
07-31-2014, 10:44 AM
I took 'as Excel.Workbook' off of my Dim statements, and now it works fine. Not sure I understand that, but I've got what I need.