[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『VBA:プリンターの切り替えをしたい』(ヒロスズ)
印刷方法で・・・。
エクセルVBAにて、プリンターの切り替えをしたいのですが、どうすればよいでしょうか?
今現在、プリンターが3台LANにて使い分けております。VBAを使いエクセルのあるファイルだけマクロにてボタンを使い、他はレーザーでこのファイルだけドットプリンターを使いたいのです。そういうマクロはどうするのでしょうか?
Dim myPrinter AS string
myPrinter = Application.ActivePrinter '現在のプリンタ名を取得 Application.ActivePrinter = "変更したいプリンタ名" '印刷処理 Application.ActivePrinter = myPrinter
こんな感じです。 (INA)
マクロの記録で「プリンタを切り替え」て「印刷」する 動作を記録すればはっきりしたプリンタへのパスが得られます。 (KAMIYA)
' 私が使っているプリンターです。
' 参考にしていただければ幸いです。
' 印刷は、プレビュー画面にしてあります。
'
Dim MSG As String, ACTIVE_P As String, COUNT As Single Dim MOJISUU As Long, PORT_0 As String
ACTIVE_P = Application.ActivePrinter ' 変数にアクティブプリンターを読込む MOJISUU = Len(Trim(ACTIVE_P)) ' 文字数を判定 PORT_0 = Right(ACTIVE_P, 3) ' 後ろから3文字のポート番号を取込む ACTIVE_P = Left(ACTIVE_P, (MOJISUU - 3)) ' ポート番号を除いた分を取込む
' メッセージでプリンターを確認
MSG = "アクティブプリンター " & ACTIVE_P & PORT_0 & MOJISUU MsgBox (MSG)
' 初期値の設定
COUNT = 0 ' エラー処理(プリンターのポートが違うとエラーになるため) On Error GoTo Err_1
' EPSON PX-1004
Application.ActivePrinter = "EPSON PX-1004 on Ne" & PORT_0 ActiveWindow.SelectedSheets.PrintOut Copies:=1, Preview:=True, _ ActivePrinter:="EPSON PX-1004 on Ne" & PORT_0, Collate:=True
Top_1:
GoTo End_1
' エラー処理ルーチン(ポート番号を読込む)※ 8ポートあるものとして検索
Err_1:
COUNT = COUNT + 1 If Err.Number = 1004 Then Select Case COUNT Case Is = 1 PORT_0 = "01:" Resume Case Is = 2 PORT_0 = "02:" Resume Case Is = 3 PORT_0 = "03:" Resume Case Is = 4 PORT_0 = "04:" Resume Case Is = 5 PORT_0 = "05:" Resume Case Is = 6 PORT_0 = "06:" Resume Case Is = 7 PORT_0 = "07:" Resume Case Is = 8 PORT_0 = "08:" Resume Case Else MSG = "アクティブプリンター " & Application.ActivePrinter MsgBox (MSG) End Select
MSG = "プリンターが見つかりません!" & Application.ActivePrinter & Err.Number MsgBox (MSG)
Else
End If
End_1:
End Sub
(minobito)
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.