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 3 years have passed since last update.

テスト47

Last updated at Posted at 2021-10-02
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const BM_CLICK As Long = &HF5
Private Const WM_ACTIVATE As Long = &H6
Private Const WM_SETTEXT As Long = &HC

Sub PDF_Print()
'(^ω^)
'Windows Script Host Object Modelを参照設定
Dim wsh As IWshRuntimeLibrary.WshShell
Dim strShell As String
Dim printName As String
Dim pw As String
Dim objWSH As Object
Dim hwnd As Long
Dim edt_hwnd As Long
Dim btn_hwnd As Long
'(・ω:;.:…サラサラ
pw = "111111"
Set wsh = New IWshRuntimeLibrary.WshShell

'Const filePath = "C:\Users\User\Desktop\VBA練習\PDF\test.pdf"
Const filePath = "C:\Users\User\Desktop\VBA練習\PDF\test4.pdf"
'------------------------------------------------
printName = "Microsoft Print to PDF"
'以下のようにポート番号を入れて実行しようとすると正しく動作しない
'   printName = "Microsoft Print to PDF on Ne01:"
'------------------------------------------------

strShell = "AcroRd32.exe /t " & filePath & " " & printName
wsh.Run (strShell)

If pw <> "" Then

    Do Until hwnd <> 0
    
        hwnd = FindWindow("#32770", "パスワード")
        
        Sleep (50)
        DoEvents
    
    Loop

    hwnd = FindWindowEx(hwnd, 0&, "GroupBox", vbNullString)

    If hwnd <> 0 Then
    
        edt_hwnd = FindWindowEx(hwnd, 0&, "RICHEDIT50W", vbNullString)

        btn_hwnd = FindWindowEx(hwnd, 0&, "Button", "OK")
        
        If (edt_hwnd <> 0) And (btn_hwnd <> 0) Then

            Call SendMessage(edt_hwnd, WM_SETTEXT, 0&, pw)
            Call SendMessage(btn_hwnd, WM_ACTIVATE, 1, 0&)
            Call SendMessage(btn_hwnd, BM_CLICK, 0, 0&)
        
        End If

    End If

Set wsh = Nothing

End Sub

'Acessメモ
'画面左側
'「すべてのACCESSオブジェクト」で右クリック
'↓
'ナビゲーションオプション
'↓
'表示オプションの
'・隠しオブジェクトの表示
'・システムオブジェクトの表示
'のチェックをはずす

'ObjAccess.Run "プロジェクト名.プロシージャ_A"

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?