Import CSV and XLSX

emukiss10

Board Regular
Joined
Nov 17, 2017
Messages
201
Hello,

I have a little problem. I want to import files to excel - different files to different sheets but I cannot manage to set two extensions at once.

I like Excel to import chosen XLSX and CSV to separate sheets. I dont know how to set more than one extension.

Im useing this code to import xls files

Code:
    Dim xFilesToOpen As Variant
    Dim i As Integer
    Dim xWb As Workbook
    Dim xTempWb As Workbook
    Dim xDelimiter As String
    Dim xScreen As Boolean
    On Error GoTo ErrHandler


    xDelimiter = "|"
    xFilesToOpen = Application.GetOpenFilename("Wycena i Eru (*.xls), *.xls", , "", , True)
    If TypeName(xFilesToOpen) = "Boolean" Then
        MsgBox "No files were selected", , ""
        GoTo ExitHandler
    End If
    i = 1
    Set xTempWb = Workbooks.Open(xFilesToOpen(i))
    xTempWb.Sheets(1).Copy
    Set xWb = Application.ActiveWorkbook
    xTempWb.Close False


    Do While i < UBound(xFilesToOpen)
        i = i + 1
        Set xTempWb = Workbooks.Open(xFilesToOpen(i))
        With xWb
            xTempWb.Sheets(1).Move After:=.Sheets(.Sheets.count)
        End With
    Loop
ExitHandler:
    Set xWb = Nothing
    Set xTempWb = Nothing
ErrHandler:

best regards
w.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try changing the "*.xls" references to "*.*"
 
Upvote 0
Thank You.

But I would like to narrow choices to just CSV and XLSX.

To many to choose from and people are going crazy :)
 
Upvote 0
But I would like to narrow choices to just CSV and XLSX.

To many to choose from and people are going crazy
I don't think that is easily done, unless they both contain the same prefix.
If you don't want to show all, then I suggest maybe doing two OpenFileName blocks, one for the XLSX and one for the CSV.
Maybe preface it with another input box asking them what type of file they wish to open, and then go to the correct block based on that.
 
Upvote 0
Ok, Thank You. I thaught i may be a little tricky.
Yes, I am not sure how to do both (or even if it is possible).
But it should be pretty straightforward to do the extra Input Box asking what kind of file that they would like to imports, and then present the correct OpenFile dialog.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,121
Members
452,381
Latest member
Nova88

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