Results 1 to 5 of 5

Thread: Import CSV Files Excel Multiple Select GetOpenFilename won't work argh!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    3

    Exclamation Import CSV Files Excel Multiple Select GetOpenFilename won't work argh!!!

    Please please help me work out what is wrong with the below code. I simply want to select several files and process them into one worksheet in the same way; i recorded the processing, modified it to include and array in Y and put multiselect to true but it simply won't get past the GetOpenFilename part

    Code:
    Private Sub CommandButton1_Click()
           Dim X As Variant
    
           'Opens the dialog
           X = Application.GetOpenFilename("CSV Files (*.csv),*.csv,Text Files (*.txt),*.txt", 4, "Select Files", , True)
           
           
    
           'Loops through every file that is selected and opens each one
           For Y = 1 To UBound(X)
    
    With ActiveSheet.QueryTables.Add(Connection:= _
            "X(Y)", Destination _
            :=Range("1,(Y+(Y-1))"))
            .Name = "X(Y)"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .TextFilePromptOnRefresh = False
            .TextFilePlatform = xlMacintosh
            .TextFileStartRow = 2
            .TextFileParseType = xlDelimited
            .TextFileTextQualifier = xlTextQualifierDoubleQuote
            .TextFileConsecutiveDelimiter = True
            .TextFileTabDelimiter = True
            .TextFileSemicolonDelimiter = False
            .TextFileCommaDelimiter = True
            .TextFileSpaceDelimiter = True
            .TextFileOtherDelimiter = """"
            .TextFileColumnDataTypes = Array(9, 5, 9, 1, 9, 9)
            .Refresh BackgroundQuery:=False
            .UseListObject = False
        End With
    
    Next Y
    
    End Sub
    
    Private Sub UserForm_Click()
    
    End Sub
    Last edited by Siddharth Rout; May 7th, 2013 at 08:53 AM. Reason: Added Code tags

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Import CSV Files Excel Multiple Select GetOpenFilename won't work argh!!!

    Welcome to VBForums

    Thread moved from the 'VB.Net' forum to the 'Office Development/VBA' forum.

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Import CSV Files Excel Multiple Select GetOpenFilename won't work argh!!!

    Welcome to the Forums

    There is nothing wrong with your GetOpenFilename code. The problem is with this line

    Code:
    With ActiveSheet.QueryTables.Add(Connection:= "X(Y)"
    
    '
    '~~> Rest of the code
    '
    The X(Y) is within quotes and hence it become a string and not a "variable"

    Try it without the quotes. For example

    Code:
    With ActiveSheet.QueryTables.Add(Connection:= X(Y)
    
    '
    '~~> Rest of the code
    '
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    3

    Re: Import CSV Files Excel Multiple Select GetOpenFilename won't work argh!!!

    I'm also trying to make a macro that will insert two cells between each of my data points (in a column) so that they are in line with other parts of my data which is more complete.... Any ideas why the below won't work?

    Thank you for your time.

    Sub FinalAttempt()

    Dim S As Long
    Dim X


    X = ActiveCell

    Range("X:X.End(xlDown)").Select

    S = Selection.Rows.Count

    Dim L As Integer

    For L = 1 To L = S Step 1

    Range("ActiveCell:ActiveCell.End(xlDown)").Select

    S = Selection.Rows.Count


    Selection.Cut ("ActiveCell.Offset(3,0)")

    Cells("X.Offset(L+4,0)").Select

    Next L

    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    3

    Re: Import CSV Files Excel Multiple Select GetOpenFilename won't work argh!!!

    Also I now have as you suggested (see below) but still stuck on OpenFileName

    Am using Mac Excel VBA recent edition 2011 or perhaps 2012

    Private Sub CommandButton1_Click()
    Dim X As Variant

    'Opens the dialog
    X = Application.GetOpenFilename("CSV Files (*.csv),*.csv,Text Files (*.txt),*.txt", 4, "Select Files", , True)



    'Loops through every file that is selected and opens each one
    For Y = 1 To UBound(X)

    With ActiveSheet.QueryTables.Add(Connection:=X(Y), Destination _
    :=Range("1,(Y+(Y-1))"))
    .Name = "X(Y)"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = xlMacintosh
    .TextFileStartRow = 2
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = True
    .TextFileTabDelimiter = True
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = True
    .TextFileSpaceDelimiter = True
    .TextFileOtherDelimiter = """"
    .TextFileColumnDataTypes = Array(9, 5, 9, 1, 9, 9)
    .Refresh BackgroundQuery:=False
    .UseListObject = False
    End With

    Next Y

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width