salh90
08-30-2016, 12:38 PM
I am trying to figure out how to switch between Internet Explorer and the workbook that I am running the macro in.
here is my entire code.
'Declare mouse events
Public Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As LongPtr
Public Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
'Declare sleep
Declare Function BlockInput Lib "USER32.dll" (ByVal fBlockIt As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Public Sub SUBNAME1()
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = False
apiShowWindow objIE.hwnd, SW_MAXIMIZE
objIE.Navigate "THE WEBSITE I AM ACCESSING"
Application.Wait Now + TimeValue("0:00:05")
SetCursorPos 35, 145
Sleep 50
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 50
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
SetCursorPos 35, 180
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 50
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Sleep 300
SetCursorPos 960, 930
Sleep 2000
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 500
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Sleep 50
This is where I need to switch from IE back to the main wkb running the Macro.
Dim rng As Range
Set rng = Range("E3")
While (rng.Text <> "")
If rng.Offset(0, -1).Text <> "" Then GoTo gtNext
rng.Select
rng.Copy
This is where it copies the rng data and attempts to paste it into internet explorer.
gtNext:
Set rng = rng.Offset(1, 0)
Wend
End Sub
here is my entire code.
'Declare mouse events
Public Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As LongPtr
Public Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
'Declare sleep
Declare Function BlockInput Lib "USER32.dll" (ByVal fBlockIt As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Public Sub SUBNAME1()
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = False
apiShowWindow objIE.hwnd, SW_MAXIMIZE
objIE.Navigate "THE WEBSITE I AM ACCESSING"
Application.Wait Now + TimeValue("0:00:05")
SetCursorPos 35, 145
Sleep 50
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 50
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
SetCursorPos 35, 180
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 50
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Sleep 300
SetCursorPos 960, 930
Sleep 2000
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 500
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Sleep 50
This is where I need to switch from IE back to the main wkb running the Macro.
Dim rng As Range
Set rng = Range("E3")
While (rng.Text <> "")
If rng.Offset(0, -1).Text <> "" Then GoTo gtNext
rng.Select
rng.Copy
This is where it copies the rng data and attempts to paste it into internet explorer.
gtNext:
Set rng = rng.Offset(1, 0)
Wend
End Sub