SetForegroundWindow
is a Windows API function that takes and returns LongPtr
on 64-bit Office, and Long
on 32 bit Office, so you need to account for that using conditional compilation constants. See this for reference.
Option Explicit
#If VBA7 Then
Public Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
#Else
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
#End If
Sub Test()
Dim objIE As InternetExplorer
Set objIE = New InternetExplorer
#If VBA7 Then
Dim HWNDSrc As LongPtr
#Else
Dim HWNDSrc As Long
#End If
HWNDSrc = objIE.hwnd
SetForegroundWindow HWNDSrc
End Sub