Results 1 to 6 of 6

Import CSV files to new tabs

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-08-2011
    Location
    Leicester, England
    MS-Off Ver
    Excel 2007
    Posts
    157

    Import CSV files to new tabs

    The situation I am in is that I have a couple of .csv files with different names that follow the trend like kieranqueryone, kieranquerytwo and so on.

    What I want to do is from a dashboard I have, at a click of a button it opens the fileopen dialog and let's me import these csv files to excel but for each file I open it puts it to a new tab with the csv file's name if that's possible at all?

    I've searched the forum but cannot find anything like it, if someone could get me started or direct me to something I might have missed I would duely appreicate it.
    where I am up to:
    Private Sub Add_Multiple_Sheets_Click()
    
    Application.DisplayAlerts = False
    
    Dim SingleFile As Variant    'holds full path and filename
    
    'Get filenames to open
    SingleFile = Application.GetOpenFilename("Query Files (*.csv*),*csv", , "Select .csv Files...", , True)
    
    'Exit procedure if user clicks cancel
    If TypeName(SingleFile) = "Boolean" Then
        Exit Sub
    End If
    
    
    Dim ifile As Integer    'file counter
    ifile = 1
    Do While ifile <= UBound(SingleFile)
        
        'Open file
        Dim myfile As String
        Dim secAutomation As MsoAutomationSecurity
        secAutomation = Application.AutomationSecurity
        Application.AutomationSecurity = msoAutomationSecurityForceDisable
        Workbooks.Open SingleFile(ifile)
        Application.AutomationSecurity = secAutomation
        myfile = ActiveWorkbook.Name
        
        'Check file contains Course Booking sheet
        Dim wsSheet As Worksheet
        Dim CorrectType As Boolean
        
        On Error Resume Next
            For Each wsSheet In Worksheets
               If wsSheet.Name = "KieranQueryOne" Then
                    CorrectType = True
                End If
            Next wsSheet
        On Error GoTo 0
    no idea if what I have so far will work, I've editted it slightly from when I imported excel sheets. but I need to say if wsSheet.Name = "KieranQueryOne" or "KieranQueryTwo" etc or a way around that so I can just import any file name then say put each csv files information to a new tab
    Last edited by kieranbop; 03-14-2012 at 04:11 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1