Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub ImportCSV()
- Dim ws As Worksheet
- Dim qt As QueryTable
- Dim csvFilePath As String
- ' Укажите путь к CSV-файлу
- csvFilePath = "C:\path\to\your\file.csv"
- ' Укажите лист, куда будет загружен файл
- Set ws = ThisWorkbook.Sheets("Sheet1")
- ' Очистка предыдущих данных
- ws.Cells.Clear
- ' Создание QueryTable для импорта CSV
- Set qt = ws.QueryTables.Add(Connection:="TEXT;" & csvFilePath, Destination:=ws.Range("A1"))
- ' Настройки импорта
- With qt
- .TextFileConsecutiveDelimiter = False
- .TextFileCommaDelimiter = True ' Разделитель - запятая (для других используйте TextFileOtherDelimiter)
- .TextFileOtherDelimiter = ";" ' Для CSV с другим разделителем (например, точка с запятой)
- .TextFilePlatform = xlWindows
- .TextFileStartRow = 1
- .TextFileParseType = xlDelimited
- .TextFileConsecutiveDelimiter = False
- .Refresh BackgroundQuery:=False
- End With
- ' Освобождение памяти
- Set qt = Nothing
- Set ws = Nothing
- MsgBox "Импорт завершен!", vbInformation
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment