問題描述
Nhấn OK trên cửa sổ cảnh báo bật lên qua 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.
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?
Thank you very much!
參考解法
方法 1:
Just add Application.DisplayAlerts = False
prior to the call, and set it back to True
after.
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.
方法 2:
You can add a DoCmd.SendKeys
BEFORE the instruction that generates the dialog.
方法 3:
You should use mouse click function Before it maximize window so x,y cordinates of ok buttons remain same Use windows lib 32
(by maximladus、nunzabar、iDevlop、bhupendra singh)