У меня есть код для ввода данных из таблицы Excel на веб-сайт, который открывается в Google Chrome. Код работает абсолютно нормально. Я просто хочу, чтобы как Excel, так и Chrome окна располагались сверху рядом во время работы макроса. Окно Excel отлично позиционируется влево, но на хромированном окне это не влияет. Я не мог найти решение после того, как много гуглил. Chrome и ввод данных контролируются Selenium.
'This part has code to import window resizing functions.
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowRect Lib "user32" ( _
ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Private Declare Function MoveWindow Lib "user32" ( _
ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function BringWindowToTop Lib "user32" (ByVal hWnd As Long) As Long
Sub Selenuim_Upload()
Dim test1 As Long, test2 As Long
test1 = Timer
Dim obj As New WebDriver
obj.Start "chrome", ""
obj.Get "https://csa.xyz.com/"
obj.FindElementById("ContentPlaceHolder1_ddlUserProfile").SendKeys ("Collector")
obj.FindElementById("ContentPlaceHolder1_btn_login").Click
obj.Get "https://csa.xyz.com/Collector_view.aspx/Default.aspx/"
'------------------------------------------------------------------------
' This part calculates window sizes and moves Excel window to left and IE window to right.
Dim hWnd As Long
Dim R As RECT, LW As RECT, RW As RECT
'Get the size of the deskop
If GetWindowRect(GetDesktopWindow, R) = 0 Then Exit Sub
'Calculate the left and right side
LW = R
LW.Right = R.Left + (R.Right - R.Left) / 2
RW = R
RW.Left = R.Right - (R.Right - R.Left) / 2
'Move Excel to the left
hWnd = FindWindow("XLMAIN", vbEmpty)
With LW
MoveWindow hWnd, .Left, .Top, .Right - .Left, .Bottom - .Top, True
End With
BringWindowToTop hWnd
'Move Chrome to the right
hWnd = FindWindow("Chrome_WidgetWin_1", vbEmpty)
With RW
MoveWindow hWnd, .Left, .Top, .Right - .Left, .Bottom - .Top, True
End With
BringWindowToTop hWnd
'------------------------------------------------------------------------
'Select Invoice Number in Serch By box
obj.FindElementById("ContentPlaceHolder1_ddlSearch").SendKeys ("Inv Number")
Range("A1").Select
'REST OF THE CODE CONTINUES FROM HERE