掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
通常使うプリンタをプログラムから変更するには? (ID:114602)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
SetDefaultPrinter では、一部出来ないようなことを聞いたことがあります。 下の方法を使用すれば大丈夫だと思います。 Option Explicit Private Declare Function GetVersion Lib "kernel32.dll" () As Long Private Declare Function WriteProfileString Lib "kernel32.dll" Alias _ "WriteProfileStringA" (ByVal lpszSection As String, _ ByVal lpszKeyName As String, ByVal lpszString As String) As Long Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const HWND_BROADCAST As Long = &HFFFF& Private Const WM_WININICHANGE As Long = &H1A& Private Function isWindowsNT() As Boolean isWindowsNT = IIf(GetVersion() And &H80000000, False, True) End Function Private Sub SetWindowsDefaultPrinter( _ ByVal DeviceName As String, ByVal DriverName As String, ByVal Port As String) Dim param As String param = DeviceName & "," & DriverName & "," & Port WriteProfileString "windows", "device", param If isWindowsNT Then 'Windows NT/2000 SendMessage HWND_BROADCAST, WM_WININICHANGE, 0&, ByVal 0& Else 'Windows 95/98/Me SendMessage HWND_BROADCAST, WM_WININICHANGE, 0&, ByVal "windows" End If Printer.EndDoc End Sub Private Sub Form_Load() Dim tp As Printer For Each tp In Printers If tp.DeviceName = "変更したいプリンタ" Then SetWindowsDefaultPrinter tp.DeviceName, tp.DriverName, tp.Port Exit For End If Next tp End Sub
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.