Add CSV file to filter? VBA

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
644
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

I have some code which allows me to select a file to import.

However, I'd like to add .csv files to the list of files that can be shown in the list of files in the 2nd last row of code below.

Does anyone know how to do that, please?

VBA Code:
Sub ImportFile()

Dim fd As FileDialog
Dim filewaschosen As Boolean
Dim ExcelFile As Workbook
Dim iWB As Workbook

Application.ScreenUpdating = False

Set ExcelFile = ActiveWorkbook
Set fd = Application.FileDialog(msoFileDialogOpen)
fd.Filters.Clear
'fd.Filters.Add "xlsx files", "*.xlsx"
fd.Filters.Add "Custom Excel Files", "*.xlsx, *.xlsm, *.xls"
fd.AllowMultiSelect = False
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi,

just add ( ,*.xxx ) for the file extension you want, inside the quotes?

Code:
fd.Filters.Add "Custom Excel Files", "*.xlsx, *.xlsm, *.xls, *.csv"
 
Upvote 0
I had tried that, but it didn't work?

Please see below - do you know of any other reason why it wouldn't work?

VBA Code:
Sub ImportFile()

Dim fd As FileDialog
Dim filewaschosen As Boolean
Dim ExcelFile As Workbook
Dim iWB As Workbook

Application.ScreenUpdating = False

Set ExcelFile = ActiveWorkbook
Set fd = Application.FileDialog(msoFileDialogOpen)
fd.Filters.Clear
'fd.Filters.Add "xlsx files", "*.xlsx"
fd.Filters.Add "Custom Excel Files", "*.xlsx, *.xlsm, *.xls, *.csv"
 
Upvote 0

Forum statistics

Threads
1,214,858
Messages
6,121,960
Members
449,057
Latest member
FreeCricketId

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