Hello folks,
Can someone help me adapt this macro/module (that imports fixed width files into excel) for use in Access? I have pulled in the excel library, but do not know where to go from here. Point of interest: data is not in a .txt file and the header row starts in row 3.
Thanks so much for your help!!
Sub OpenTextFile() Dim strFilename As String 'Show the open dialog and pass the path to the selected 'file to the String variable "strFilename" strFilename = Excel.Application.GetOpenFilename 'If the user cancels, exit the routine. If strFilename = "False" Then Exit Sub 'Display a message box to let us see what the variable was set to. MsgBox strFilename Const xlFixedWidth = 2 Set objExcel = CreateObject("Excel.Application")objExcel.Visible = TrueobjExcel.Workbooks.OpenText _ strFilename, , , xlFixedWidth, , , , , , , , , Array(Array(0, 1), Array(4, 1), Array(9, 1), Array(23, 1), Array(30, 1), Array(33, 1), Array(42, 1), Array(48, 1), Array(51, 1), Array(54, 1), Array(64, 1), Array(70, 1), Array(80, 1), Array(87, 1)) End Sub
Can someone help me adapt this macro/module (that imports fixed width files into excel) for use in Access? I have pulled in the excel library, but do not know where to go from here. Point of interest: data is not in a .txt file and the header row starts in row 3.
Thanks so much for your help!!
Sub OpenTextFile() Dim strFilename As String 'Show the open dialog and pass the path to the selected 'file to the String variable "strFilename" strFilename = Excel.Application.GetOpenFilename 'If the user cancels, exit the routine. If strFilename = "False" Then Exit Sub 'Display a message box to let us see what the variable was set to. MsgBox strFilename Const xlFixedWidth = 2 Set objExcel = CreateObject("Excel.Application")objExcel.Visible = TrueobjExcel.Workbooks.OpenText _ strFilename, , , xlFixedWidth, , , , , , , , , Array(Array(0, 1), Array(4, 1), Array(9, 1), Array(23, 1), Array(30, 1), Array(33, 1), Array(42, 1), Array(48, 1), Array(51, 1), Array(54, 1), Array(64, 1), Array(70, 1), Array(80, 1), Array(87, 1)) End Sub