gpt4 book ai didi

excel - 将 Chrome 窗口向右移动,将当前 excel 向左移动

转载 作者:行者123 更新时间:2023-12-04 19:50:35 25 4
gpt4 key购买 nike

我有一个代码,用于执行从 Excel 工作表到在谷歌浏览器中打开的网站的数据输入。代码工作得很好。我只想在宏运行时将 excel 和 chrome 窗口并排放置在顶部。 excel 窗口完全向左定位,但对 chrome 窗口没有影响。谷歌搜索了很多之后,我无法找出解决方案。 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

最佳答案

我想出了解决办法。感谢这个线程 link .我使用 winlister(由 nirsoft 开发)找到宏打开的那个网站的窗口标题。然后用 hWnd = FindWindow("Chrome_WidgetWin_1", vbEmpty) 中的 vbEmpty 替换它,所以最后一行代码就像 hWnd = FindWindow("Chrome_WidgetWin_1", "https://csa.xyz .com/Collector_view.aspx/Default.aspx/- Google Chrome") .

现在代码可以并排排列 excel 和 chrome 窗口。

关于excel - 将 Chrome 窗口向右移动,将当前 excel 向左移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55533043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com