は、任意のテキストファイル(かかわらず、これらの行の内容)から上面15行を削除手順の一例です。それは一度に1行で動作するので、任意の大きなファイルを扱うことができるはずです。
Sub removeTopLines()
Dim srcFile As String, nSrc As Integer ' source file (read from)
Dim dstFile As String, nDst As Integer ' destination file (write to)
Dim textLine As String
Const LINES_TO_SKIP = 15
Dim lineCounter As Long
srcFile = "c:\opt\src.txt"
dstFile = "c:\opt\dst.txt"
nSrc = FreeFile
Open srcFile For Input As #nSrc
nDst = FreeFile
Open dstFile For Output As #nDst
lineCounter = 1
Do Until EOF(nSrc)
Line Input #nSrc, textLine
If lineCounter > LINES_TO_SKIP Then
Print #nDst, textLine
End If
lineCounter = lineCounter + 1
Loop
Close #nDst
Close #nSrc
End Sub
あなたはhow to traverse a directory tree hereの例を見ることができる、あるいはあなただけのすべてのそれらのファイルのパス名のリストを取得し、一度それを一つのファイルを与える別のループからこのプロシージャを呼び出すことができます。
アップデート:ここでは行数は「時間」とそれ以降の行だけのコピーを含む文字列を検索する代わりに、別のバージョンがあります。
Sub removeTopLinesAfter()
Dim srcFile As String, nSrc As Integer ' source file (read from)
Dim dstFile As String, nDst As Integer ' destination file (write to)
Dim textLine As String, strAfter As String
strAfter = "time"
Dim copyLines As Boolean
srcFile = "c:\opt\src.txt"
dstFile = "c:\opt\dst.txt"
nSrc = FreeFile
Open srcFile For Input As #nSrc
nDst = FreeFile
Open dstFile For Output As #nDst
copyLines = False
Do Until EOF(nSrc)
Line Input #nSrc, textLine
If Not copyLines Then
copyLines = InStr(textLine, strAfter) > 0
Else
Print #nDst, textLine
End If
Loop
Close #nDst
Close #nSrc
End Sub
何これはExcelとの関係があるのでしょうか?どの時点でExcelがこれに関与していますか?それはバッチスクリプトを使用してこれを行うには大丈夫だ場合 –
、あなたをhttp://stackoverflow.com/questions/11428692/batch-file-to-delete-first-3-lines-of-a-text-fileすることができます参照してください。サブフォルダ内の複数のファイルを処理するようにも強化してください –
メモ帳にはマクロ機能はありません。ツールに関する前提条件なしに問題を述べてから試してみてください。 – Richard