0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Word VBA】PDF形式で保存するマクロ

Last updated at Posted at 2021-01-03

WordファイルをワンクリックでPDF保存する

WordファイルをワンクリックでPDF保存するマクロを作りました。
PDFファイルは開いたWordファイルと同じ場所に保存されます。

ソース

Option Explicit

Sub SavePDF()
    Dim FilePath As String
    FilePath = ActiveDocument.Path + "\"
    
    Dim Buf As Variant
    Dim FileName As String
    Buf = Split(ActiveDocument.Name, ".")
    FileName = Buf(0) + ".pdf"

    ActiveDocument.ExportAsFixedFormat _
        OutputFileName:=FilePath + FileName, _
        ExportFormat:=wdExportFormatPDF, _
        OpenAfterExport:=False, _
        OptimizeFor:=wdExportOptimizeForPrint, _
        Range:=wdExportAllDocument, _
        From:=1, _
        IncludeDocProps:=True, _
        BitmapMissingFonts:=True
End Sub

設定方法

1. Microsoft Wordを起動し、何かしらの文章を開く(空白の文章でもOK)

2. Alt + F11キーを押し、Visual Basic Editorを開く

3. Normalの標準モジュール(赤枠部)で右クリック → 挿入 → 標準モジュール
image0.png

4. 追加したモジュールにソースをコピペ
image1.png

5. ファイル → オプションからWordのオプションを開く
クイックアクセスツールバーのカスタマイズ画面を開き、
① コマンドの選択をマクロにする
② 今回作成したマクロを選択する
③ 追加を押す
④ 追加されたものを選択し、変更ボタンを押す。アイコンと名前を変更する
⑤ アイコンと名前が変更されたものになったことを確認する
⑥ Word上部にPDF保存ボタンが追加される
image2.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?