通过 VBA 在弹出的警报窗口上按 OK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15548939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Press OK on pop-up alert window via VBA
提问by maximladus
Having an issue, I have written a Macro ,that refreshes every 2 min, to upload data from a webpage and the last step of my Macro is using "Text to column" function so that it will be splitted into columns nicely.
有一个问题,我写了一个宏,每 2 分钟刷新一次,从网页上传数据,我的宏的最后一步是使用“文本到列”功能,以便将其很好地拆分为列。
The problem appears here everytime it gets to executes this "Text to column" it asks if I want to overwrite the columns(and I DO), but I need to press manually OK.
每次执行此“文本到列”时都会出现问题,它会询问我是否要覆盖列(我确实要),但我需要手动按“确定”。
Is there any way to make VBA press this OK button in the alert?
有没有办法让 VBA 在警报中按下这个 OK 按钮?
Thank you very much!
非常感谢!
采纳答案by Patrick Honorez
You can add a DoCmd.SendKeys
BEFORE the instruction that generates the dialog.
您可以DoCmd.SendKeys
在生成对话框的指令之前添加一个。
回答by nunzabar
Just add Application.DisplayAlerts = False
prior to the call, and set it back to True
after.
只需Application.DisplayAlerts = False
在调用之前添加,然后将其设置回True
之后。
http://msdn.microsoft.com/en-us/library/office/aa175241%28v=office.11%29.aspx
http://msdn.microsoft.com/en-us/library/office/aa175241%28v=office.11%29.aspx
Update: I just ran a test and it does not prompt me by default. Can you post the code you're using? I simply did:
更新:我刚刚运行了一个测试,默认情况下它不会提示我。你能发布你正在使用的代码吗?我只是做了:
Public Sub Test()
Dim r As Range
Set r = ActiveWorkbook.Sheets(1).Columns("A:A")
r.TextToColumns Destination:=Range("B1")
End Sub
This linksays the DisplayAlerts
solution has worked in for others.
此链接表示该DisplayAlerts
解决方案已对其他人有效。
回答by bhupendra singh
You should use mouse click function Before it maximize window so x,y cordinates of ok buttons remain same Use windows lib 32
您应该在最大化窗口之前使用鼠标单击功能,以便确定按钮的 x,y 坐标保持不变使用 windows lib 32