Hello darkhorse4321,
Here is the updated version of your macro.
Private Sub CommandButton1_Click()
Dim Filename As String
Dim I As Integer
Dim myFile As Variant
Dim myFileName As String
If ComboBox1.ListIndex = -1 Then Exit Sub
Filename = ComboBox1.Value
myFile = Application.GetOpenFilename("Text Files,*.txt")
'Check if Cancel was clicked
If myFile = False Then Exit Sub
'Extract the file name from the path
myFileName = Right(myFile, Len(myFile) - InStrRev(myFile, "\"))
'Check that the file names match. This is not case sensitive
If StrComp(myFileName, Filename, vbTextCompare) <> 0 Then
MsgBox "Not a Valid File.", vbInformation, "unable to continue"
Exit Sub
End If
Workbooks.OpenText Filename:=myFile, _
Origin:=xlWindows, _
StartRow:=1, _
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(4, 1), Array(10, 1), _
Array(26, 1), Array(27, 1), _
Array(50, 1), Array(58, 1)), _
TrailingMinusNumbers:=True
ActiveSheet.Move After:=Workbooks("retriveFile.xls").Sheets(1)
ActiveWindow.WindowState = xlMaximized
End Sub
Bookmarks