How to create a Macro or VBA that imports an Excel file (variable name) which has a variable location.

Galapagos15

Board Regular
Joined
Sep 16, 2015
Messages
100
How can I create a Macro or VBA that imports an Excel file (has variable name) and the location of the file is also variable? i.e When the user runs the Macro/VBA it prompts the user to locate the file and then once it's selected Access will import it into the table named "Table1". Thanks in advance!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Check out the File Picker. It will enable user to located and select a file and the path is returned to your code if a file is selected. I think the latest version is 4 and can be called by Application.FileDialog(4) but I might be wrong about that. I presume you want to import the file as a linked table, or put the path in some table. I doubt you are saying you actually want to import the file as an object in a table. To link, use DoCmd.Transferspreadsheet, acLink,, "Table1", "Path to file", True, "SheetName!RangeOfData"
My guess is that your sheet will need a named range that is dynamic unless you set some arbitrary large range so that you don't leave data behind.
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,252
Members
451,757
Latest member
iours

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