Hi All,
I am trying to create a very simple user form which does converts multiple .txt to .xlsx.
The problem i am having is when i try to convert the file i got this error: "Compile error: ByRef argument type mismatch".
Any ideas how to sole the issue?
The user form contains only 2 buttons.
Code:
Dim filesToConvert As Collection
Private Sub ToggleButton1_Click()
Dim fileDialog As fileDialog
Set fileDialog = Application.fileDialog(msoFileDialogFilePicker)
fileDialog.AllowMultiSelect = True
fileDialog.Title = "Select .txt file to convert"
If fileDialog.Show = -1 Then
For Each file In fileDialog.SelectedItems
Next
End If
End Sub
Private Sub ToggleButton2_Click()
For Each file In filesToConvert
ConvertTxtToXls file
Next file
Set filesToConvert = New Collection
MsgBox "Conversion completed!", vbInformation, [OK!]
Sub ConvertTxtToXls(txtFilePath As String)
Workbooks.OpenText txtFilePath, , , xlDelimited, , , True
ActiveWorkbook.SaveAs Replace(txtFilePath, ".txt", ".xlsx"), xlOpenXMLWorkbook
ActiveWorkbook.Close
End Sub
Private Sub UserForm_Click()
Set filesToConvert = New Collection
End Sub
Bookmarks