aaa*_*aaa 8 excel vba excel-vba sendkeys
我sendkey
用来访问Power Query并连接到SharePoint文件夹.一切顺利,直到Power Query Data Preview对话框出现.
sendkey
对话框出现后如何允许继续?我正在使用按钮启动宏并使用Excel 2016.
Option Explicit
Sub Button1_Click()
Dim spPath As String
Dim strkeys As String
spPath = "" 'SharePoint Link
strkeys = "%APNFO" & spPath & "{Enter}{TAB 4}{Enter}"
'stops at first{Enter}, {TAB 4}{Enter} for EDIT
Call SendKeys(strkeys)
End Sub
Run Code Online (Sandbox Code Playgroud)
更新
也尝试了sendkey
两次True
但结果相同,停止在对话框中.
Option Explicit
Sub Button1_Click()
Dim spPath As String
Dim strkeys As String
Dim strkeys2 As String
spPath = ""
strkeys = "%APNFO" & spPath & "{Enter}"
strkeys2 = "{TAB 4}{Enter}"
Call SendKeys(Trim(strkeys), True)
Call SendKeys(Trim(strkeys2), True)
Debug.Print strkeys2
End Sub
Run Code Online (Sandbox Code Playgroud)
UPDATE2
我尝试了@peh的建议,使用sleep()
和Application.wait()
.我发现一旦宏被初始化,sendkey1
启动和停止了Application.wait()
.只有在等待时间结束后sendkey1
才会被处理.一旦sendkey1
开始,sendkey2
也开始了.
也尝试添加DoEvents
,sendkey1
工作完美.但是只有在点击后的取消按钮,Application.wait()
并且sendkey2
将开始.
Call SendKeys(Trim(strkeys))
Debug.Print Now & "Send Key 1"
'Do Events
Application.wait (Now + TimeValue("0:00:10"))
Call SendKeys(Trim(strkeys2), True)
Debug.Print Now & "Send Key 2"
Run Code Online (Sandbox Code Playgroud)
潘内尔
如果对话框每次都相同,或者在标题中包含一致的文本字符串,您可以使用它的标题来检测何时使用此函数在循环中使用定时器搜索合理数量的对话框的时间:
Private Function GetHandleFromPartialCaption(ByRef lWnd As Long, ByVal sCaption As String) As Boolean
Dim lhWndP As Long
Dim sStr As String
GetHandleFromPartialCaption = False
lhWndP = FindWindow(vbNullString, vbNullString) 'PARENT WINDOW
Do While lhWndP <> 0
sStr = String(GetWindowTextLength(lhWndP) + 1, Chr$(0))
GetWindowText lhWndP, sStr, Len(sStr)
sStr = Left$(sStr, Len(sStr) - 1)
If InStr(1, sStr, sCaption) > 0 Then
GetHandleFromPartialCaption = True
lWnd = lhWndP
Exit Do
End If
lhWndP = GetWindow(lhWndP, GW_HWNDNEXT)
Loop
End Function
Run Code Online (Sandbox Code Playgroud)
其中sCaption是对话框的名称.然后在你的主体代码中使用:
If GetHandleFromPartialCaption(lhWndP, "Your Dialogue Box Caption") = True Then
SendKeys(....
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
674 次 |
最近记录: |