excel - VBA 中 "Windows"键的 Application.Sendkeys 是什么?

标签 excel vba sendkeys

没有“windows”键的文档:https://learn.microsoft.com/en-us/office/vba/api/excel.application.sendkeys

我想要组合“Windows+UP”键来最大化事件窗口。 因此,我尝试使用“Ctrl+Esc”作为 Windows 键 + {UP}:Application.SendKeys ("^({ESC}{UP})") 但它没有用。

有没有一种方法可以使用 API、dll 等发送 Windows key ,而无需使用 AutoIt 等外部程序。

最佳答案

Is there a way to send windows key using API, dll etc without using external programs like AutoIt

是的,您可以使用 FindWindowShowWindow用于最大化窗口的 API。这比使用 Sendkeys 更可靠。

举个例子

Option Explicit

Private Declare PtrSafe Function ShowWindow Lib "user32" _
(ByVal hwnd As LongPtr, ByVal nCmdSHow As Long) As Long

Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr

Private Const SW_SHOWMAXIMIZED = 3

Sub MaximizeAWindow()
    Dim hwnd As Long
    Dim Caption As String
    
    Caption = "THIS IS THE CAPTION OF THE WINDOW"
    
    hwnd = FindWindow(vbNullString, Caption)
    
    If hwnd <> 0 Then
        ShowWindow hwnd, SW_SHOWMAXIMIZED
    Else
        MsgBox "Unable to find the window. Is the caption correct?"
    End If
End Sub

您可能也对 GetForegroundWindow 感兴趣和 GetWindowText API获取当前事件窗口的标题?

关于excel - VBA 中 "Windows"键的 Application.Sendkeys 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74683104/

相关文章:

excel - 使用 excel 或 powershell 将一长串数字转换为存在范围的范围组

c# - 在 excel 列之间插入列

excel - 关闭源文件时,无法在 for 循环中重用内容

vba - 将多列中的值合并为一列

internet-explorer - VBA 与 Internet Explorer 的交互

r - 使用 R 转换 Excel 文件中存储为文本的数字

php - 使用 PHP 将 Excel 数据从特定行和列解析到 MySQL

SQL 字符串太长

Python Selenium - 属性错误 : WebElement object has no attribute sendKeys

vb6 - SendKeys "^f"无法与其他快捷键一起使用