Excel VBA:导入CSV并重命名工作表

我在MS Excel中有以下macros:我可以单击一个macrosbutton,然后可以select一个.csv文件和macros导入文件以正确的格式到名为“testing”和一个计数的新工作表。

如果新工作表与.csv文件具有相同的名称,这对我来说真的很好 – 是否有人知道如何在这里实现?

Sub GetCSVList() Dim dlgOpen As FileDialog Set dlgOpen = Application.FileDialog(msoFileDialogFilePicker) With dlgOpen .AllowMultiSelect = True ''Start in .InitialFileName = "C:\Test" .Show End With For Each fname In dlgOpen.SelectedItems ImportCSV fname Next End Sub Sub ImportCSV(fname) Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count)) ws.Name = "test" & Worksheets.Count + 1 With ws.QueryTables.Add( _ Connection:="TEXT;" & fname, _ Destination:=Range("A1")) .Name = "Test" & Worksheets.Count + 1 .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .TextFilePromptOnRefresh = False .TextFilePlatform = 65001 .TextFileStartRow = 1 .TextFileParseType = xlDelimited .TextFileTextQualifier = xlTextQualifierDoubleQuote .TextFileConsecutiveDelimiter = False .TextFileTabDelimiter = False .TextFileSemicolonDelimiter = False .TextFileCommaDelimiter = True .TextFileSpaceDelimiter = False .Refresh BackgroundQuery:=False '.UseListObject = False End With End Sub