Sendkeys将不会在宏中间运行 [英] Sendkeys will not run in middle of macro
问题描述
我正在尝试使用VBA自动从Hyperion中提取数据(我是VBA的新手).我必须在工作表1上选择一个单元格区域,按" Alt,X,S,R,让它提取数据,然后转到下一个工作表并重复.我遇到的问题是宏在选项卡中运行并根据需要突出显示单元格,但是sendkey(所有五个实例)在完整宏的末尾而不是在每个步骤之后运行.任何帮助,将不胜感激.宏1-5与不同的工作表名称完全相同.
I am attempting to use VBA to automate the pulling of data from Hyperion (I am new to VBA). I have to select a cell range on Sheet 1, "press" Alt,X,S,R, allow it to pull the data, then go to the next sheet and repeat. The problem I am experiencing is that the macro runs through the tabs and highlights the cells as necessary, however the sendkeys (all five instances) run at the end of the full macro rather than after each step. Any help would be appreciated. Macro 1-5 are the exact same with different sheet names.
我当前拥有的代码:
Sub RunAllMacros()
Macro1
Macro2
Macro3
Macro4
Macro5
End Sub
Sub Macro1()
Sheets("Sheet 1").Select
Range("C5:H15").Select
Range("H15").Activate
Selection.ClearContents
Range("A1:H15").Select
Range("H15").Activate
SendKeys ("%"), True
SendKeys ("x"), True
SendKeys ("s"), True
SendKeys ("r"), True
Application.Wait (Now + #12:00:01 AM#)
End Sub
推荐答案
尝试进行此修改.
Dim dTILL as double
SendKeys ("%(xsr)"), True
dTill = Now + TimeSerial(0,0,2)
Do While dTILL>Now: DoEvents: Loop
这应该使消息泵能够允许外部进程赶上.
That should get the message pump to allow outside processes to catch up.
这篇关于Sendkeys将不会在宏中间运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!