投稿日 | : 2002/11/26(Tue) 14:06 |
投稿者 | : 花ちゃん |
Eメール | : |
URL | : |
タイトル | : Re^5: VBからCSV印刷 |
これで一度試して見て下さい。
Private Sub DataPrint()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\WINDOWS\デスクトップ\Book1.csv")
Set xlSheet = xlBook.Worksheets(1)
'列の幅を設定
xlSheet.Range("C1", "X1").ColumnWidth = 5.75
'シートの印刷設定
With xlSheet.PageSetup
.PaperSize = xlPaperA4 '用紙サイズをA4
'印刷の向き 横=xlLandscape 縦 = xlPortrait
.Orientation = xlLandscape
'各余白をセンチ(Cm)単位で設定
' 注意 ↓Application でも参照できるが開放されない
.LeftMargin = xlApp.CentimetersToPoints(2)
.RightMargin = xlApp.CentimetersToPoints(2)
.TopMargin = xlApp.CentimetersToPoints(2.5)
.BottomMargin = xlApp.CentimetersToPoints(2.5)
.HeaderMargin = xlApp.CentimetersToPoints(1)
.FooterMargin = xlApp.CentimetersToPoints(1)
End With
'CSV印刷
xlSheet.PrintOut
'Excelのウインドウ(Book)を表示する
xlApp.Visible = True
'エクセルの終了
xlApp.Quit
'オブジェクトを開放
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
End Sub