Option Explicit
[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If"]#If[/URL] VBA7 Then
Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
Private Declare PtrSafe Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As LongPtr, ByVal wFlag As Long) As LongPtr
Private Declare PtrSafe Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As LongPtr, lpdwProcessId As Long) As Long
Private Declare PtrSafe Function GetParent Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
Private Declare PtrSafe Function GetShellWindow Lib "user32" () As LongPtr
[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else"]#Else[/URL]
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetShellWindow Lib "user32" () As Long
[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End"]#End[/URL] If
Private Const WM_PASTE = &H302
Private Const GW_HWNDPREV = 3
Sub Copy_into_NotePad()
Dim lr As Long, PID As Long
lr = Sheets("Copied Summary").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Copied Summary").Range("A1:D" & lr).Copy
PID = Shell("notepad.exe", vbMinimizedNoFocus) 'vbNormalFocus)
Call SendMessage(GetNextWindow(HwndFromPID(PID), 5), WM_PASTE, True, 0)
End Sub
[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If"]#If[/URL] VBA7 Then
Private Function HwndFromPID(ByVal PID As Long) As LongPtr
Dim lTempHwnd As LongPtr
[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else"]#Else[/URL]
Private Function HwndFromPID(ByVal PID As Long) As Long
Dim lTempHwnd As Long
[URL="https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End"]#End[/URL] If
Dim lTempPid As Long
lTempHwnd = GetShellWindow
Do While lTempHwnd
If GetParent(lTempHwnd) = 0 Then
Call GetWindowThreadProcessId(lTempHwnd, lTempPid)
If lTempPid = PID Then
HwndFromPID = lTempHwnd
Exit Do
End If
End If
lTempHwnd = GetNextWindow(lTempHwnd, GW_HWNDPREV)
DoEvents
Loop
End Function