プロが教えるわが家の防犯対策術!

マクロ駆け出しです。お助けください。
やりたいことは、特定のプリンタを指定し印刷設定を行う(印刷はしない)ということです。
マクロの記録機能を使い、印刷設定は作れたのですが、特定のプリンタが選択されないということに困っています。プリンタの選択方法などもネットで調べたのですが、組み合わせ方がわからずにうまく動作しないという状態です。勉強不足で大変恐縮ですが、お助けいただけると助かります。
よろしくお願いします。

<使いたいプリンター情報>
プリンターの名称:Microsoft XPS Document Writer
プリンターのポート:XPSPort

<作ってみた印刷設定>

Option Explicit

Sub 印刷設定()
'
' 印刷設定 Macro
'
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = "$A$1:$I$61"
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0)
.RightMargin = Application.InchesToPoints(0)
.TopMargin = Application.InchesToPoints(0)
.BottomMargin = Application.InchesToPoints(0)
.HeaderMargin = Application.InchesToPoints(0)
.FooterMargin = Application.InchesToPoints(0)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlPortrait
.Draft = False
.PaperSize = xlPaperA4
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
.EvenPage.LeftHeader.Text = ""
.EvenPage.CenterHeader.Text = ""
.EvenPage.RightHeader.Text = ""
.EvenPage.LeftFooter.Text = ""
.EvenPage.CenterFooter.Text = ""
.EvenPage.RightFooter.Text = ""
.FirstPage.LeftHeader.Text = ""
.FirstPage.CenterHeader.Text = ""
.FirstPage.RightHeader.Text = ""
.FirstPage.LeftFooter.Text = ""
.FirstPage.CenterFooter.Text = ""
.FirstPage.RightFooter.Text = ""
End With
Application.PrintCommunication = True
End Sub

A 回答 (3件)

こんばんは。


どのような運用をなさっているのかわかりませんが
わたしは通常は印刷しないで印刷ビューに引き渡します。
Application.CommandBars.ExecuteMso "PrintPreviewAndPrint"
あとはOSがプリンターの選択を聞いてきます。
当然、Microsoft XPS Document Writerも見えます。
それで駄目なんでしょうか。
    • good
    • 3

一例です


MyPrt = Application.ActivePrinter'現在のプリンターを覚えておく
Application.ActivePrinter = "Microsoft XPS Document Writer on Ne00:"
'プリンターの切り替え
ActiveSheet.PrintPreview
'印刷プレビュー
ActiveSheet.PrintOut printtofile:=True, PrToFileName:=ThisWorkbook.Path & "\○○.xps"
’印刷する場合
Application.ActivePrinter = MyPrt’元のプリンターに戻す。
    • good
    • 1

こちらが参考になるでしょう。



Excel 2010/2013 の VBA でアクティブプリンターを切り替えるには
http://uonuma.biz/blog/19049

プリンタ名の 「on Ne00:」の部分を
レジストリを見ずに簡単に調べるには
目的のプリンタを「通常使うプリンタ」にした上で
イミディエイトウィンドウで

? Application.ActivePrinter
Microsoft XPS Document Writer on Ne00:

自分だけが使うならこれで十分ですが、
そうでなければ、結構、むずかしそうです。
    • good
    • 2

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!