| 
    
     |  | このような「項目ごとの印刷」に向いているのは、編集機能のオプションを うまく使う方法だと思います。
 >改ページして見出しと明細印字
 "明細"というのが、具体的に何なのか分からないので、仮にC列の集計結果
 (個数の計)だとします。
 以下のようなコードで出来ると思います。実際に実行する場合、まずテスト段階で
 変更する必要があるところは、テキストの保存先フォルダーのパスで、定数 SvF
 の値です。テスト時には印刷ではなく、改ページプレビューが七秒間表示されます。
 結果がよければ With ActiveWorkbook.Worksheets(1) 〜 End With までの
 >   Application.ScreenUpdating = True
 >   ActiveWindow.View = xlPageBreakPreview
 >   Application.Wait Time + TimeValue("00:00:07")
 >   ActiveWindow.View = xlNormalView
 を削除し、'.PrintOut Copies:=1 の先頭の "'" を消してコメント化を
 解除し、プリンターの準備をしてから実行して下さい。
 
 Sub Print_MyCSV()
 Dim FR As Range
 Dim MyF As String
 Const SvF As String = _
 "C:\Documents and Settings\User\My Documents"
 
 ChDir SvF
 With Application
 MyF = .GetOpenFilename("テキストファイル(*.csv),*.csv")
 If MyF = "False" Then Exit Sub
 .ScreenUpdating = False
 .DisplayAlerts = False
 End With
 Workbooks.Open MyF
 With ActiveWorkbook.Worksheets(1)
 On Error Resume Next
 .Range("A1", .Range("IV1").End(xlToLeft)).SpecialCells(4) _
 .EntireColumn.Delete
 On Error GoTo 0: If Err.Number <> 0 Then Err.Clear
 .Rows(1).Insert xlShiftDown
 .Range("A1:C1").Value = Array("Data1", "Data2", "Data3")
 .Range("A1").Subtotal 1, xlCount, Array(3), _
 True, True, xlSummaryAbove
 Set FR = .Range("A:A").Find("総合計", , xlValues)
 If Not FR Is Nothing Then
 FR.EntireRow.Hidden = True: Set FR = Nothing
 End If
 .Rows(1).Hidden = True
 Application.ScreenUpdating = True
 ActiveWindow.View = xlPageBreakPreview
 Application.Wait Time + TimeValue("00:00:07")
 ActiveWindow.View = xlNormalView
 '.PrintOut Copies:=1
 .Cells.EntireRow.Hidden = False
 .Cells.RemoveSubtotal
 .Rows(1).Delete xlShiftUp
 .DisplayAutomaticPageBreaks = False
 .Parent.Close False
 End With
 With Application
 .ScreenUpdating = True
 .DisplayAlerts = True
 ChDir .DefaultFilePath
 End With
 End Sub
 
 
 |  |