importing a file into a spreadsheet

viper

Active Member
Joined
Feb 15, 2002
Messages
382
I've written this code into the click event of a command button but I get a Compile Error: Argument not optional.
What am I doing wrong. I am wanting to import a labor file to input the hrs worked by each employee into my spreadsheet. The filters are set up only because I'm not sure of the labor file name quite yet and just want the code to work first.


'Set up list of file filters
Filter = "Text Files (*.txt),*.txt," & _
"Lotus Files (*.prn),*.prn," & _
"Comma Separated Files (*.csv),*.csv," & _
"ASCII Files (*.asc),*.asc," & _
"All Files (*.*),*.*"
'Display *.* by default
FilterIndex = 5

'Set the dialog box caption
Title = "Select a File to Import"

'Get the filename
Filename = Application.GetOpenFilename(Filter, _
FilterIndex, Title)

'Exit if dialog box canceled
If Filename = False Then
MsgBox "No file was selected!"
Exit Sub
End If
'Open the file
Workbooks.Open FileName

Thanks,
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,213,563
Messages
6,114,329
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top