Importing a file

G

Guest

Guest
If I use the following code where do I put it? Can I attach it to a command button?

Sub GetImportFileName()
'Set up the file filters
Filter = "Text Files (*.txt),*.txt," & _
"Lotus Files (*.prn),*.prn," & _
"Comma Separated Files (*.csv),*.csv," & _
"ASCII Files (*.asc), *.asc," & _
"All Files (*.*),*.*"

'Display *.* default
FilterIndex = 5

'set dialog box caption
Title = "Select a File to import"

'get filename
FileName = Application.GetOpenFilename(Filter, _ FilterIndex, Title)

'Exit on cancel
If FileName = Fales Then
MsgBox = "No file selected"
Exit Sub
End If
'Open file
Workbooks.Open FileName

I'm trying to import a file and create a worksheet that I can pull data from.

Thanks,
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
In design mode right click on the button and select "view code" Paste your code here.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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