如何使用 VBA 更改外部应用程序的屏幕大小

How to change screen size of an external application using VBA

我试过下面的代码来调整 Excel

的屏幕尺寸
Sub win()
Dim myWindow1 As Window, myWindow2 As Window
Set myWindow1 = ActiveWindow
Set myWindow2 = myWindow1.NewWindow
With myWindow1
    .WindowState = xlNormal
    .Top = 0
    .Left = 0
    .Height = Application.UsableHeight
    .Width = Application.UsableWidth * 0.25
End With
With myWindow2
    .WindowState = xlNormal
    .Top = 0
    .Left = (Application.UsableWidth * 0.25) + 1
    .Height = Application.UsableHeight
    .Width = Application.UsableWidth * 0.75
End With
End Sub

但是我想更改 google chrome 的屏幕大小。如果不使用 shell 打开新的 Chrome 应用程序怎么办? 我想更改已打开 Chrome 应用程序

的屏幕大小

您可以使用 User32 库中的函数来控制外部 windows。这是一个 Google Chrome "New Tab" window:

这样做的例子
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Sub SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Sub Resize_Chrome()
Dim ChromeHandle As Long
ChromeHandle = FindWindow(vbNullString, "New Tab - Google Chrome")
SetWindowPos ChromeHandle, -1, 0, 0, 600, 600, &H10
End Sub

这会将 window 设置为左​​上角 (0,0),像素大小为 600 x 600 (600,600)

有关 SetWindowPos 函数的详细信息,请参阅 https://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396