简体   繁体   English

通过VBA在弹出警报窗口中按确定

[英]Press OK on pop-up alert window via VBA

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. 这里出现问题每次它执行这个“文本到列”它询问我是否要覆盖列(我做),但我需要手动按OK。

Is there any way to make VBA press this OK button in the alert? 有没有办法让VBA在警报中按下这个OK按钮?

Thank you very much! 非常感谢你!

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 link says the DisplayAlerts solution has worked in for others. 此链接表明DisplayAlerts解决方案已经为其他人提供了帮助。

您可以在生成对话框的指令之前添加DoCmd.SendKeys

您应该使用鼠标单击功能在它最大化窗口之前使x,y ok按钮的坐标保持相同使用windows lib 32

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM