VBA- Selecting file to copy a range into existing sheet

FancyCorndog

New Member
Joined
Aug 9, 2012
Messages
10
Hi all,

I'm trying to accomplish something that I can't seem to figure out in VBA. It's a little hard for me to explain, but I will try my best.

What I want to do is prompt the user with a Windows Explorer window to browse for a file. The file that the user navigates to will be a .csv file that I am going to copy a specific range from.

I've been able to create an Explorer window like this:

Shell("explorer.exe ", vbNormalFocus)

This allows the user to browse for and open a file. But what I want is for that file to be my source for copying, not necessarily opened (or maybe opened, copied, and then closed in the background)


The goal here is for the user to be able to browse and select a file, and once they select it my macro should grab the data (at a range that I already know) and put it into an existing sheet in the current workbook.

1) User hits the "Import File" button
2) Windows Explorer pops up and allows them to navigate to a file.
3) Data from the file that they choose (which is always a .csv file structured in a similar manner) is automatically copied into an existing sheet in the workbook.


Is there a way to accomplish this?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
You can do this without Explorer.

You can Open the file for Input and read the data you need. (Look under Open VBA in the help file.)

Can you explain how the CSV file is formatted and where the data is? Or provide a sample file for testing.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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