breynolds0431
Active Member
- Joined
- Feb 15, 2013
- Messages
- 303
- Office Version
- 365
- 2016
- Platform
- Windows
Hi. Trying to have files run the fixed-width automatically with Workbooks.opentext. The problem I'm running into is trying to get an open file dialog to open so the user can select the text file to convert. Below is what I have so far, but it stops running when the file opens to the import wizard.
Thanks for any help on this.
Thanks for any help on this.
Code:
Sub CTConvert()
Dim myfile As String
Workbooks.OpenText filename:=myfile, _
Origin:=437, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array( _
Array(0, 1), Array(1, 1), Array(14, 1), Array(24, 1), Array(33, 1), Array(41, 1), Array(55, _
1), Array(65, 1), Array(66, 1), Array(74, 1), Array(82, 1), Array(102, 1), Array(112, 1), _
Array(121, 1), Array(129, 1), Array(143, 1), Array(153, 1), Array(154, 1), Array(170, 1)) _
, TrailingMinusNumbers:=True
myfile = GetFile(myfile)
Workbooks(myfile).Close
End Sub
Public Function GetFile(ByVal strPath As String) As String
Application.Dialogs(xlDialogOpen).Show Arg1:="*.*"
End Function