VBA - Place uploaded .csv file name into cell on certain sheet

前端 未结 1 1438
情深已故
情深已故 2021-01-24 14:50

I was wondering if there is a way to take the .csv file that is selected and place the name into a cell on the \'Summary\' sheet. Here is the code to upload the .csv file:

相关标签:
1条回答
  • 2021-01-24 15:16

    Applying the solution from the link I provided in the comment to the question (you would need to add a reference to Microsoft Scripting Runtime (Tools > References in the IDE):

    Dim ws As Worksheet, strFile As String
    
    Set ws = ActiveWorkbook.Sheets("Input Raw Data") 'set to current worksheet name
    
    strFile = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please select text file...")
    
    With ws.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=ws.Range("A1"))
        .TextFileParseType = xlDelimited
        .TextFileCommaDelimiter = True
        .Refresh
    End With
    
    
    Dim fso as new FileSystemObject
    Dim fileName As String
    fileName = fso.GetFileName(strFile)
    Worksheets("Summary").Range(Your Range Here).Value = fileName
    
    0 讨论(0)
提交回复
热议问题