automating copying data from .csv file to a xlsm file with a dialog box

sairampappu

New Member
Joined
Nov 19, 2017
Messages
7
Hi

I am trying to import a .csv file into a .xlsm sheet and copy the whole data. Actually I have code in such a way that the input file(raw data .csv file) is open (should be activated), then only the macro is running. So I need to modify the code in a way that " If I press select file button, a dialog box should open then I should select any .csv input file and the whole data .
Please help me out.

Thanks,
Sai
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
This will allow you to select a csv file & it will then open it.
Code:
Sub OpenFile()

    Dim FName As String
    
    FName = Application.GetOpenFilename(FileFilter:="CSV Files (*.csv), *.csv", Title:="Select a .csv file", MultiSelect:=False)
    If FName = False Then
        MsgBox "no file selected"
        Exit Sub
    Else
        Workbooks.Open FName
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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