Button to import file

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi,

I know there is a lot of data on these boards about this, but i'm totally confused. I would like to but a button in A1 that will ask for the file location, then import the selected excel file into the current worksheet starting at A3.

Thanks!!!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Put the button in A1 manually. Use FileDialog (msoFileDialogFilePicker) or GetOpenFilename to prompt for the file. Using the macro recorder, import an Excel file manually to A3 using the Data - Import External Data - Import Data menu (Excel 2003, should be similar for other versions). Edit the VBA generated to include the file prompt and use the file name selected by the user instead of the hard-coded file name used by the macro recorder. Finally, assign the button to the macro.
 
Upvote 0
Thanks!! I am able to record the Macro, but i get lost when I try to edit it. Also, the file will be different each time. When i use the Import Data function, the query is attached to my worksheet and updated automatically?
 
Upvote 0
Also, the file will be different each time.
That's why I said to edit the macro.

When i use the Import Data function, the query is attached to my worksheet and updated automatically?
Delete the query after it has imported the data using something like:
Code:
ActiveSheet.QueryTables(1).Delete
which assumes the query is on the active sheet - if not, change the ActiveSheet sheet reference to the appropriate sheet.

Post the code inside CODE tags if you need help with it.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,391
Members
448,957
Latest member
Hat4Life

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