Well, FWIW, you could try this code. You will have to set a reference to Microsoft Scripting Runtime"
What it does is read from one file, test the length of the first line and writes to another file.
Loops through reading and writing the remaining lines.
Deletes the original text file
Renames the new text file toi the old text file name.
There are ways to read in the complete text file, edit it, then write it out to the same file...... but I don't know how to do that..
---- Warning - try on a test Text file -----
( this runs in A2K - don't know about A2K7 )
Code:
Option Compare Database
Option Explicit
Public Sub Filetest()
Const ForReading = 1
Const ForWriting = 2
Dim objFSO As Object
Dim OrigName As String
Dim NewName As String
Dim objFileOrig 'Orig file
Dim objFileNew 'New file
Dim ThePath As String
Dim iLineNumber As Long
Dim strLine As String
Dim strNewContents As String
'could use open/save code to select a file check/import
OrigName = "TestFixedFile.txt"
'any name not in use. It will be overwritten. And renamed
NewName = "AAA123.txt"
ThePath = CurrentProject.Path
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFileOrig = objFSO.OpenTextFile(ThePath & "\" & OrigName, ForReading)
'create the new text file
Set objFileNew = objFSO.CreateTextFile(ThePath & "\" & NewName, True)
objFileNew.Close
Set objFileNew = objFSO.OpenTextFile(ThePath & "\" & NewName, ForWriting)
iLineNumber = 0
Do Until objFileOrig.AtEndOfStream
strNewContents = ""
strLine = objFileOrig.ReadLine
iLineNumber = iLineNumber + 1
If iLineNumber = 1 Then
If Len(strLine) <> 353 Then
strNewContents = Right("0000000" & strLine, 353)
End If
Else
strNewContents = strLine
End If
objFileNew.WriteLine strNewContents
Loop
objFileOrig.Close
objFileNew.Close
' delete original text file
Kill ThePath & "\" & OrigName
'rename file to original text file name
Name ThePath & "\" & NewName As ThePath & "\" & OrigName
'-----------------------
' for testing comment out or remove
MsgBox "Done"
'-----------------------
'continue with automation import code
End Sub