ChatGPT suggests
Code:
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, _
ByVal lParam As LongPtr) As LongPtr
Private Const WM_CLOSE = &H10
Sub ClosePDFWindow()
Dim hWnd As LongPtr
Dim windowTitle As String
windowTitle = "YourFileName.pdf - Adobe Acrobat Reader" ' Adjust as needed
hWnd = FindWindow(vbNullString, windowTitle)
If hWnd <> 0 Then
Call SendMessage(hWnd, WM_CLOSE, 0, 0)
Else
MsgBox "Window not found."
End If
End Sub
That is 64bit code, so you will need to modify for 32bit.
https://learn.microsoft.com/en-us/of...tions-overview
Would work for any window as well, so could be an Excel file, Browser window, whatever, as long as you know it's name.