Excelファイルをプリンタに印刷する方法を記載します。
シートをプリンタに印刷する
Dim xlApp As Excel.Application = New Excel.Application()
Dim xlBook As Excel.Workbook = xlApp.Workbooks.Open("C:\work\myBook.xls")
Dim xlSheet As Excel.Worksheet = xlBook.Worksheets("Sheet1")
'ヘッダー、フッターの記入
With xlSheet.PageSetup
.Orientation = Excel.XlPageOrientation.xlLandscape
.CenterHeader = "&12&B" & " ヘッダータイトル " & "&12&B&U"
.RightHeader = Now().Year & "年" & Now.Month & "月" & Now.Day & "日"
.CenterFooter = "&P / &N ページ"
.Zoom = 100
End With
xlApp.Application.DisplayAlerts = False
--------------------------------------------------------------------
'ファイルをセーブする
xlBook.SaveAs(Filename:="C:\work\myBook4.xls", FileFormat:=Excel.XlFileFormat.xlExcel8) 'ファイルに保存
--------------------------------------------------------------------
'プリンタに印刷する
xlSheet.PrintOut()
--------------------------------------------------------------------
'プレビューサイズを指定する
'Dim xlWindow = xlApp.ActiveWindow
'xlWindow.View = Excel.XlWindowView.xlPageBreakPreview
'xlSheet.PageSetup.Zoom = 100
'xlWindow.Zoom = 75
--------------------------------------------------------------------
'印刷プレビューを表示する
xlSheet.Activate()
xlApp.Visible = True
xlSheet.PrintPreview()
--------------------------------------------------------------------
xlBook.Close()
xlApp.Application.DisplayAlerts = True
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)