Add CSV file to filter? VBA

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
634
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
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

daverunt

Well-known Member
Joined
Jul 9, 2009
Messages
1,891
Office Version
  1. 2013
Platform
  1. Windows
Hi,

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

Code:
fd.Filters.Add "Custom Excel Files", "*.xlsx, *.xlsm, *.xls, *.csv"
 

Mr2017

Well-known Member
Joined
Nov 28, 2016
Messages
634
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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"
 

daverunt

Well-known Member
Joined
Jul 9, 2009
Messages
1,891
Office Version
  1. 2013
Platform
  1. Windows
No reason it shouldn't work. Works for me.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,374
Messages
5,624,319
Members
416,020
Latest member
ANDREAC247

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
Top