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関連

    ドラッグ&ドロップしたOfficeファイルをPDFに変換するVBScript

    複数のExcelファイルをPDFに一括変換する必要があったので、簡単な…

  2. Office関連

    Acrobat XIを操作してテキスト認識操作を行うVBAマクロ

    マクロからAcrobatを操作する場合「PDFファイル上のフィールドの…

  3. Office アドイン

    [Officeアドイン]Word JavaScript APIの機能紹介

    Office Dev Center - Changelogを見ると分か…

  4. Office関連

    PowerShellからNetOfficeを使ってWordやPowerPointを操作する方法

    前回の記事関連で、WordやPowerPointもドンとこいで…

  5. Office関連

    ページごとにPNG形式で出力するWordマクロ(Word 2013)

    ※ この情報はOffice 2013 カスタマー プレビュー版を元にし…

コメント

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

Time limit is exhausted. Please reload CAPTCHA.

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

Translate

最近の記事

アーカイブ

PAGE TOP