导入保留UTF-8格式的CSV文件

时间:2017-08-10 19:34:40

标签: excel vba csv utf-8

我从单独的工作表中的文件夹导入一批csv文件,但是当我导入文件时,我的新数据丢失了数字的前导零,并且还丢失了其UTF-8格式。有没有办法在保持前导零和UTF-8格式的同时导入csv文件?

以下是我的vba

Option Explicit
Sub ImportCSVs()

Dim fPath   As String
Dim fCSV    As String
Dim wbCSV   As Workbook
Dim wbMST   As Workbook

Set wbMST = ThisWorkbook
fPath = "C:\mycsvfiles\Q3 2017\"                  'path to CSV files, include the final \
Application.ScreenUpdating = False  'speed up macro
Application.DisplayAlerts = False   'no error messages, take default answers
fCSV = Dir(fPath & "*.csv")         'start the CSV file listing

On Error Resume Next
Do While Len(fCSV) > 0
    Set wbCSV = Workbooks.Open(fPath & fCSV)                    'open a CSV file
    wbMST.Sheets(ActiveSheet.Name).Delete                       'delete sheet if it exists
    ActiveSheet.Move After:=wbMST.Sheets(wbMST.Sheets.Count)    'move new sheet into Mstr
    Columns.AutoFit             'clean up display
    fCSV = Dir                  'ready next CSV
Loop

Application.ScreenUpdating = True
Set wbCSV = Nothing
End Sub

提前感谢一百万!如果我能提供更多信息,请告诉我

0 个答案:

没有答案