我有一個宏,可以在excel中打開.txt文件,有沒有辦法在打開時對它們進行分隔?注:多個文件處於打開狀態,所以類似於「|」分隔的活動工作簿,不知道如何分割。 UserInput位於我的字典中,是文件選取器。VBA,用「|」分隔excel文件打開
這是我目前有:
Sub Rec()
Dim wb As Workbook, fileNames As Object, errCheck As Boolean
Dim ws As Worksheet, wks As Worksheet, wksSummary As Worksheet
Dim y As Range, intRow As Long, i As Integer
' Turn off screen updating and automatic calculation
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
'get user input for files to search
Set fileNames = CreateObject("Scripting.Dictionary")
errCheck = UserInput.FileDialogDictionary(fileNames)
If errCheck Then
Exit Sub
End If
For Each Key In fileNames 'loop through the dictionary
On Error Resume Next
Set wb = Workbooks.Open(fileNames(Key))
If Err.Number <> 0 Then
Set wb = Nothing ' or set a boolean error flag
End If
On Error GoTo 0 ' or your custom error handler
Next 'End of the fileNames loop
Set fileNames = Nothing
' Reset system settings
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = True
.Visible = True
End With
End Sub
任何幫助,將不勝感激。
在使用「數據>>文本」來打開一個管道分隔文件時記錄一個宏。這會給你一些如何處理這個問題的想法。 –
它能夠在第一個文件上工作,關於如何循環它們的任何想法? – Jonnyboi