按定界符划分为整个excel工作簿

时间:2019-05-08 12:58:33

标签: excel

我已将多个CSV文件组合到一个Excel工作簿中。现在,我想用分号分隔工作簿中的日期。我的问题是我无法为整个工作簿执行此操作。它仅适用于活动工作表。有没有可以解决我的问题的VBA代码?

或者以下是我的VBA代码,用于将CSV文件组合到一个excel工作簿中。有没有一种方法可以在代码中添加一些东西来做到这一点,并用分号分隔数据并将它们一次全部组合到一个工作簿中?

Sub CombineCsvFiles()
'updateby Extendoffice 20151015
Dim xFilesToOpen As Variant
Dim I As Integer
Dim xWb As Workbook
Dim xTempWb As Workbook
Dim xDelimiter As String
Dim xScreen As Boolean
On Error GoTo ErrHandler
xScreen = Application.ScreenUpdating
Application.ScreenUpdating = False
xDelimiter = "|"
xFilesToOpen = Application.GetOpenFilename("Text Files (*.csv), *.csv", , 
"Kutools for Excel", , True)
If TypeName(xFilesToOpen) = "Boolean" Then
    MsgBox "No files were selected", , "Kutools for Excel"
    GoTo ExitHandler
End If
I = 1
Set xTempWb = Workbooks.Open(xFilesToOpen(I))
xTempWb.Sheets(1).Copy
Set xWb = Application.ActiveWorkbook
xTempWb.Close False
Do While I < UBound(xFilesToOpen)
    I = I + 1
    Set xTempWb = Workbooks.Open(xFilesToOpen(I))
    xTempWb.Sheets(1).Move , xWb.Sheets(xWb.Sheets.Count)
Loop
ExitHandler:
Application.ScreenUpdating = xScreen
Set xWb = Nothing
Set xTempWb = Nothing
Exit Sub
ErrHandler:
MsgBox Err.Description, , "Kutools for Excel"
Resume ExitHandler
End Sub

0 个答案:

没有答案