Word

リボンからプリンタを選択して簡単に印刷できるようにする(Word)

今回はdynamicMenu要素のgetContent属性のコールバックを利用して、リボンからプリンタを選択して簡単に印刷できるようにする方法を紹介します(Word)。

[リボンXML]

<?xml version="1.0" encoding="utf-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon>
    <tabs>
      <tab idMso="TabHome">
        <group id="grpPrint" label="印刷" insertBeforeMso="GroupClipboard">
          <dynamicMenu id="dmuPrint" label="印刷  " size="large" imageMso="FilePrint" screentip="プリンター選択" supertip="ここをクリックして印刷するプリンターを選択してください。" getContent="dmuPrint_getContent" />
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

[標準モジュール]

Option Explicit

Private Sub dmuPrint_getContent(control As IRibbonControl, ByRef returnedVal)
  Dim d As Object
  Dim elmMenu As Object
  Dim elmButton As Object
  Dim itm As Object
  Dim i As Long
  
  i = 1
  Set d = CreateObject("Msxml2.DOMDocument")
  Set elmMenu = d.createElement("menu")
  elmMenu.setAttribute "xmlns", "http://schemas.microsoft.com/office/2006/01/customui"
  elmMenu.setAttribute "itemSize", "large"
  With CreateObject("Shell.Application")
    For Each itm In .Namespace(4).Items
      Set elmButton = d.createElement("button")
      elmButton.setAttribute "id", "btnPrinter" & i
      elmButton.setAttribute "label", itm.Name
      elmButton.setAttribute "tag", itm.Name
      elmButton.setAttribute "imageMso", "FilePrint"
      elmButton.setAttribute "onAction", "btnPrinter_onAction"
      elmMenu.appendChild elmButton
      Set elmButton = Nothing
      i = i + 1
    Next
  End With
  d.appendChild elmMenu
  returnedVal = d.XML
  Set elmMenu = Nothing
  Set d = Nothing
End Sub

Private Sub btnPrinter_onAction(control As IRibbonControl)
  Dim tmp As String
  
  tmp = Application.ActivePrinter
  Application.ActivePrinter = control.Tag
  Application.Dialogs(wdDialogFilePrint).Show
  Application.ActivePrinter = tmp
End Sub

上記コードを設定したファイルを開くと、「ホーム」タブに「印刷」グループが追加されます。

印刷」メニューからプリンタを選択することで、プリンタを選択した状態で印刷ダイアログを表示することができます。

McAf.eeで短縮URLを取得するブックマークレット前のページ

まばたきするリボン次のページ

関連記事

  1. Office関連

    アドインやテンプレートのバージョンチェックを行うVBAマクロ

    色々なアプリケーションに実装されている、「最新バージョンの確認」機能、…

  2. Office関連

    MemsourceのバイリンガルMXLIFFファイルから情報を抽出するWordマクロ

    近年翻訳業界では「Trados」や「memoQ」といった、“翻訳支援ツ…

  3. Office関連

    空白文字を一括置換するWordマクロ

    様々なWord文書を扱っていると、下図のように“同じ空白のように見えて…

  4. Office関連

    Yahoo!翻訳で文字列を翻訳するマクロ

    「Google翻訳で文字列を翻訳するマクロ」ではGoogle翻訳を利用…

  5. Office関連

    OneNoteの指定したセクションをページごとに指定した形式で出力するマクロ

    今回はOneNoteの指定したセクションをページごとに指定した形式で出…

コメント

  1. この記事へのコメントはありません。

Time limit is exhausted. Please reload CAPTCHA.

※本ページはプロモーションが含まれています。

Translate

最近の記事

アーカイブ

PAGE TOP