'========================================================================================= ' 208 アクティブプリンタを選択して設定する '----------------------------------------------------------------------------------------- '【ヒント】 ' このマクロは、おためし機能の動作用のコードを含んでいます。(概ね下半分) ' ★★★の行またはサブプロシージャーが、タイトル機能に関係するコードです。(概ね上半分) '========================================================================================= ' ◆標準モジュールのコード◆ '----------------------------------------------------------------------------------------- Option Explicit Dim 応答 As Variant '★★★ Dim タイトル As String Dim スタイル As Long Dim メッセージ As String '========================================================================================= Sub アクティブプリンタを選択して設定する() '★★★ メッセージ = "現在のプリンタ設定は " & Application.ActivePrinter & " です" & _ Chr(13) & Chr(13) & "変更しますか" 応答 = MsgBox(メッセージ, スタイル, タイトル) If 応答 = vbYes Then 'はいボタンが押されたら UserForm1.Show 'ユーザーフォームを表示する End If End Sub '----------------------------------------------------------------------------------------- '<コメント> 'ユーザーフォームのイベントマクロを見るには、プロジェクトウインドウで「UserForml」をクリックし、 '[表示]-[コード]とクリックすると見られます '----------------------------------------------------------------------------------------- Sub おためしマクロ() おためしメッセージを表示する アクティブプリンタを選択して設定する '★★★ Range("P17").Select 'カーソルを定位置へ End Sub '----------------------------------------------------------------------------------------- Private Sub おためしメッセージを表示する() Worksheets("Title").Select Range("P17").Select 'カーソルを定位置へ移動する タイトル = "500連発 第2弾 サンプルマクロ" スタイル = 36 'vbQuestion + vbYesNo End Sub '----------------------------------------------------------------------------------------- Sub Auto_Close() Application.DisplayAlerts = False '閉じる際に確認メッセージを出さない ActiveWorkbook.Close '現在開いているブックを閉じる End Sub '----------------------------------------------------------------------------------------- '========================================================================================= ' ◆UserForm1のコード◆ '----------------------------------------------------------------------------------------- Private Sub CommandButton1_Click() If UserForm1.OptionButton1.Value = True Then If Application.Version = "9.0" Then 'Excel 2000なら Application.ActivePrinter = "LPT1: の Canon BJ F200" ElseIf Application.Version = "8.0" Then 'Excel 97なら Application.ActivePrinter = "Canon BJ F200 on LPT1:" End If ElseIf UserForm1.OptionButton2.Value = True Then If Application.Version = "9.0" Then Application.ActivePrinter = "LPT1: の Canon BJC-455J" ElseIf Application.Version = "8.0" Then Application.ActivePrinter = "Canon BJC-455J on LPT1:" End If ElseIf UserForm1.OptionButton3.Value = True Then If Application.Version = "9.0" Then Application.ActivePrinter = "LPT1: の NEC PICTY80L Printer" ElseIf Application.Version = "8.0" Then Application.ActivePrinter = "NEC PICTY80L Printer on LPT1:" End If End If Unload Me 'ユーザーフォームを消す End Sub '========================================================================================= '<コメント> 'ユーザーフォームの表示方法は、標準モジュールを見てください