VBA code to pass username and password

I am trying to update some data in a SharePoint document, and when trying this in a local environment, I am not facing any problem.

But when I try to do the same on the virtual desktop, I could not do it. I populate Windows Alert to enter a username and password. I tried using "SendKeys" for this script, but that doesn't make sense.

.... SendKeys "abc\ATX123",5 SendKeys "Password1",5 SendKeys "{ENTER}",5 .... 

This snippet simply passes 'ENTER' without entering an identifier and Pwd. Can someone suggest me some possible solution?

+1
source share
2 answers

Finally, I found a way to achieve this requirement, a bit indirect, but it was the only way I could find at the end.

What I did was simple - just created one Windows Logon.vbs script to handle this popup and named vbs in VBA.

Refer to the sample below if you are looking for something like this:

Windows Script:

 'Creating an script object Set oWSH = WScript.CreateObject("WScript.Shell") 'Activating alert screen oWSH.AppActivate ("Windows Security") 'Passing the value UserName/UserID oWSH.SendKeys "USERNAME" 'ensure to complete the username with apropriate domain eg, abc/A123456 'Changing the focus to password textbox oWSH.SendKeys "{TAB}" 'Passing the value password oWSH.SendKeys "PASSWORD" 'Clicking enter to complete the screen oWSH.SendKeys "{ENTER}" 'Releasing the script object Set oWSH = Nothing 

VBA code to call the VBS script - Logon.vbs:

 Shell "WScript C:\Users\ABC\Desktop\Logon.vbs", vbNormalFocus 
+4
source

First of all, you'll want SendKeys "yourString", Boolean . As I know, the SendKeys team wants True or False be second. You can also try "tabbing" from the field to another:

 SendKeys "abc\ATX123", True SendKeys "{TAB}", True SendKeys "Password1", True SendKeys "{ENTER}", True 

if the first has not received writing, perhaps the main focus is on another component of the user form. Try tabbing to see if your Username text box is turned on when UserForm appears. Otherwise, you can also try to set the focus.

0
source

All Articles