@pop3 (pop3)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

VBAでセル値の格納先のPDF印刷をしたい

解決したいこと

VBAでEXCELのセル値(PDF格納先)を取得しPDF印刷をしたいです。

発生している問題・エラー

A2セルのPDFしか印刷されません。
A1セルも値は正しく取得されているのですが、印刷されないです。
VBA初心者のため、ご教授をお願いいたします。

### 該当するソースコード
A1セル:C:\Users\a.pdf
A2セル:C:\Users\b.pdf

'グローバル変数
Dim printFilePath As String  '印刷ファイルのフルパス

Sub PdfPrint()
    j = 1
    Do Until Worksheets("PDF印刷用").Cells(j + 0, 1) = ""
        'セルのPDF格納先を取得
        printFilePath = Worksheets("PDF印刷用").Cells(j + 0, 1)
        
        'PDFプリント
        Call PrintOut(printFilePath)
        
        j = j + 1
    Loop
End Sub

Function PrintOut(printFilePath As String)
    'Shell実行用の変数設定
    Dim wshShellObj As IWshRuntimeLibrary.WshShell
    Set wshShellObj = New IWshRuntimeLibrary.WshShell
    Dim strShellCommand As String  'Shellコマンド
    Dim ShowPrintSettings
    Dim printerName As String  'プリンタ名
    printerName = "プリンター名" '実際に使用しているものを入れています

    'PDFファイルを開く
    CreateObject("Shell.Application").ShellExecute (printFilePath)

    'プリントアウト用のコマンド設定
    strShellCommand = "Acrobat.exe /t " & printFilePath

    'プリントアウト用のコマンド実行
    wshShellObj.Run (strShellCommand)

    Set wshShellObj = Nothing
End Function
0 likes

1Answer

CreateObject("Shell.Application").ShellExecute (printFilePath)のあとa.pdfはReaderで開かれますか?

0Like

Comments

  1. @pop3

    Questioner

    PDFはa、bともに開かれるのですが、aのみ印刷がされません。
    よろしくお願いいたします。
  2. デバッグ、原因切り分けの一環としてコマンドプロンプトを開き、`Acrobat.exe /t C:¥Users¥a.pdf`と入力した場合に印刷されるかどうかを試してみてはいかがでしょうか
  3. @pop3

    Questioner

    そうですね。
    原因切り分けを行っていくようにいたします。

Your answer might help someone💌