VBA to Import CVS Files

Glasgowsmile

Active Member
Joined
Apr 14, 2018
Messages
280
Office Version
  1. 365
Platform
  1. Windows
Good Morning,

I've got the code below -- I was hoping just adding CVS to the filter would allow me to import it but it doesn't so I need to help. How can I get this code to import CVS files?
Code:
Sub ActiveRateCategory()   
   Sheets("ActvRateCat SumRpt").Range("A:M").Clear
   Dim wkbCrntWorkBook As Workbook
   Dim wkbSourceBook As Workbook
   Set wkbCrntWorkBook = ActiveWorkbook
   With Application.FileDialog(msoFileDialogOpen)
      .Filters.Clear
      .Filters.Add "Excel 2007-13", "*.xlsx; *.xls; *.xlsm; *.xlsa; *.cvs"
      .AllowMultiSelect = False
      .Show
      If .SelectedItems.Count > 0 Then
         Workbooks.Open .SelectedItems(1)
         Set wkbSourceBook = ActiveWorkbook
         wkbSourceBook.Range("A1:L100").Copy
         wkbCrntWorkBook.Sheets("ActvRateCat SumRpt").Range ("A1")
         wkbSourceBook.Close False
      End If


   End With
End Sub
 
Last edited:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Good Morning,

I've got the code below -- I was hoping just adding CVS to the filter would allow me to import it but it doesn't so I need to help. How can I get this code to import CVS files?
Code:
      .Filters.Add "Excel 2007-13", "*.xlsx; *.xls; *.xlsm; *.xlsa; *.[COLOR=#ff0000]cvs[/COLOR]"  'must be [B]csv[/B]

Try this:

Code:
Sub ActiveRateCategory()
   Sheets("ActvRateCat SumRpt").Range("A:M").Clear
   Dim wkbCrntWorkBook As Workbook
   Dim wkbSourceBook As Workbook
   Set wkbCrntWorkBook = ActiveWorkbook
   With Application.FileDialog(msoFileDialogOpen)
      .Filters.Clear
[COLOR=#0000ff]      .Filters.Add "Excel 2007-13", "*.xlsx"[/COLOR]
[COLOR=#0000ff]      .Filters.Add "Excel 2003", "*.xls"[/COLOR]
[COLOR=#0000ff]      .Filters.Add "Excel macros", "*.xlsm"[/COLOR]
[COLOR=#0000ff]      .Filters.Add "csv Files", "*.csv"[/COLOR]
[B][COLOR=#006400]      .FilterIndex = 4[/COLOR][/B]
      .AllowMultiSelect = False
      .Show
      If .SelectedItems.Count > 0 Then
         Workbooks.Open .SelectedItems(1)
         Set wkbSourceBook = ActiveWorkbook
         wkbSourceBook.Range("A1:L100").Copy
         wkbCrntWorkBook.Sheets("ActvRateCat SumRpt").Range ("A1")
         wkbSourceBook.Close False
      End If
   End With
End Sub
 
Upvote 0
Ah, thanks!

One more question -- when I do import it, it takes me to the sheet that the data was pasted to, how do I have it take the user back to the original sheet where the button for importing is?
 
Upvote 0
Ah, thanks!

One more question -- when I do import it, it takes me to the sheet that the data was pasted to, how do I have it take the user back to the original sheet where the button for importing is?

Disregard, figured it out! Thanks for the help.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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