Sendkeys command to press Windows Security button

datamster

Board Regular
Joined
Jan 25, 2016
Messages
58
Hello,

I have a workbook that receives its data from a webpage but also requires a username and password. I'd like the workbook to be run by task scheduler but the issue I'm having is when using task scheduler a windows security box opens prompting for username and password. I've checked the box for the credentials to be remembered, which it does, but a key press is required to hit OK. So far I've tried
VBA Code:
SendKeys "~", True
ActiveWorkbook.RefreshAll

Which only presses the enter key before the security window pops up and

VBA Code:
ActiveWorkbook.RefreshAll
SendKeys "~", True

has the security window popping up before the enter key is pressed and access to excel isn't allowed until the security window goes away. Is there a way to sleep the sendkey command for a few seconds and skip to the next VBA line so when the security window opens the sendkey command is being sent?
windows_Security.JPG
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
See if this helps:


The code, posted on the old forum, is difficult to read. The first part is a VBScript (.vbs file) which finds the authentication window and populates the username and password boxes, then tabs to the OK button. I expect you would only need to tab to the OK button, using oWSH.SendKeys "{TAB}" as many times as needed. Your macro runs the VBScript using the Shell command, like this:

VBA Code:
    Const Q As String = """"
    
    Shell "wscript.exe " & Q & "C:\path\to\Login.vbs" & Q
 
Upvote 0

Forum statistics

Threads
1,215,002
Messages
6,122,652
Members
449,092
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top