Excel VBA error while check logon and logout check using IE - vba

I am amature VBA programmer. I am working in a small automation.
The steps are
Open a IE browser
Navigate to a webpage
Logon using my username and password
I am using below excel VBA code to get my solution
Code snippet
Sub LoginAuto()
Dim Myhtml As IHTMLElement
Dim Myurl As String
Myurl = "http://myurl.com"
Set Mybroswer = New InternetExplorer
Mybroswer.Silent = True
Mybroswer.navigate Myurl
Mybroswer.Visible = True
Do
Loop Until Mybroswer.readyState = READYSTATE_COMPLETE
Set HTMLDOC = Mybroswer.document
HTMLDOC.all.UserName.Value = "myuser"
HTMLDOC.all.Password.Value = "mypassword"
For Each Myhtml In HTMLDOC.getElementsByTagName("button")
If Myhtml.Type = "submit" Then
Myhtml.Click:
End If
Exit For
Next
End Sub
while running above program i am getting below error
excel vba automation error the object invoked has disconnected from its clients

Is Autoit (www-autoitscript.com) an option for you? It provides lots of useful functions to automate stuff like that.
Try this
#include<IE.au3>
$sUsername = "Username"
$sPassword = "Password"
$sUrl = "http://www.yoururl.com"
$oIE = _IECreate($sUrl, 0, 1, 1, 1)
$oHWND = _IEPropertyGet($oIE, "hwnd")
WinSetState($oHWND, "", #SW_MAXIMIZE)
$oForm = _IEFormGetCollection ($oIE, 0)
$oUsername = _IEFormElementGetObjByName($oForm, 'UserName')
$oPassword = _IEFormElementGetObjByName($oForm, "Password")
_IEFormElementSetValue($oUsername, $sUsername)
_IEFormElementSetValue($oPassword, $sPassword)
_IEFormSubmit ($oForm)

Dears,
I am able to resolve my reported problem by using "SHDocVw.InternetExplorer" instead of IHTMLElement
This allows me to "Loop Until Mybroswer.readyState = READYSTATE_COMPLETE"

Related

Error 61704 during calling RFC_READ_TABLE in VBA

I am trying to connect to SAP via RFC objects:
Dim sap As Object
Set sap = CreateObject("SAP.Functions.unicode")
sap.connection.system = "xxxxxxxx"
sap.connection.Client = "700"
sap.connection.User = "USER"
sap.connection.Password = "PASS"
sap.connection.Language = "EN"
If sap.connection.Logon(1, False) <> True Then 'Try Logon
MsgBox "Cannot Log on to SAP"
End If
'*************************************************************
'Define the table specifics
'************************************************************
Dim objRfcFunc As Object
Set objRfcFunc = sap.Add("RFC_READ_TABLE") 'IN THIS LINE MY ERROR OCCURS
Internal application error - runtime error:61704
Any solutions?
It seems like my connection is OK. Could you check my connection variables?
The following code I took from here and adjusted it worked for me. Of course you have to change the connection parameters (username etc.) as well. I guess your issue is you do not have a connection in the first place.
Sub Test_RFC()
' Connect to SAP
Dim oSAP As Object
Set oSAP = CreateObject("SAP.Functions.unicode")
' Connection parameters - to be adjusted
oSAP.Connection.ApplicationServer = "1.1.1.1" ' IP des Appl-Servers (SM51->Details)
oSAP.Connection.SystemNumber = "01" ' Systemnummer, meißt im Namen des Appl-Servers enthalten
oSAP.Connection.System = "XD1" ' Entwicklungs-, Test-, Produktivsystem
oSAP.Connection.Client = "100" ' Mandant
oSAP.Connection.Language = "DE" ' Sprache "EN", "DE" ...
' RFC-Login: Show logon popup
If oSAP.Connection.Logon(0, False) = True Then
'You can only add a function module in case you have a connection
Dim oFuBa As Object
Set oFuBa = oSAP.Add("RFC_READ_TABLE")
End If
End Sub

Accessing webservice with credentials using vba

I'm working on a longer script for Access and at one point it is necessary to check a webservice for the latest version of a file (the filename). This webservice is only accessible via a browser with an URL like https://webservice.example.com:1234/Server/test.jsp?parameter=value then it is necessary to authenticate with the standard browser username password pop up.
Of course I could skip this pop up if I'd use something like https://user:password#webservice.example.com:1234/Server/test.jsp?parameter=value instead. (Note that it is not about security at this point the password only exists for the sake of having a password and it's totally acceptable to store it as clear text)
At the moment I already use the following working code to get information from another
website:
Dim appIE As Object
Dim sURL as String, infoStr as String
Set appIE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}") 'class id of InternetExplorerMedium
sURL = "https://webservice.example.com:1234/Server/test.jsp?parameter=value"
With appIE
.Navigate sURL
.Visible = False
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
infoStr = appIE.Document.getElementsByTagName("body").item.innerText
However, if I add the credentials to the URL as I would do in the browser
sURL = "https://user:password#webservice.example.com:1234/Server/test.jsp?parameter=value"
I will get the following error:
Runtime error '-2146697202 (800c000e)': method 'navigate' of object
'IWebBrowser2' failed
Does anybody know why it is failing if I add the credentials or has anybody an idea how to do this differently?
If your website requires Basic authentication, it's relatively easy to authenticate using a basic authentication header.
We need to be able to Base64 encode content, so first we need to define a helper function for that:
Public Function ToBase64(Bytes() As Byte) As String
Dim XMLElement As Object
Set XMLElement = CreateObject("Msxml2.DOMDocument.6.0").createElement("tmp")
XMLElement.DataType = "bin.base64"
XMLElement.nodeTypedValue = Bytes
ToBase64 = Replace(XMLElement.Text, vbLf, "")
End Function
Then, a second helper to create a basic authentication header:
Public Function CreateBasicAuthHeader(Username As String, Password As String) As String
'Assuming ASCII encoding, UTF-8 is harder
CreateBasicAuthHeader = "Authorization: Basic " & ToBase64(StrConv(Username & ":" & Password, vbFromUnicode))
End Function
A quick validation shows that ?CreateBasicAuthHeader("Aladdin", "OpenSesame") returns Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l, which is the expected header according to Wikipedia
Then, you can use this in the Navigate method:
Dim appIE As Object
Dim sURL as String, infoStr as String
Set appIE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}") 'class id of InternetExplorerMedium
sURL = "https://webservice.example.com:1234/Server/test.jsp?parameter=value"
With appIE
.Navigate sURL, Headers:=CreateBasicAuthHeader("MyUsername", "MyPassword")
.Visible = False
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
infoStr = appIE.Document.getElementsByTagName("body").item.innerText
This assumes that the server either expects ASCII encoding, or your username and password are both only ASCII characters and the server expects UTF-8 encoding.

Cannot Login with Excel VBA Selenium

So I am tryin to create a Script that will automatically login for me on this website:
https://teespring.com/login
This is my script so far:
Sub openBrowser()
'Open new browser
Set driver = New Selenium.ChromeDriver
'Navigate to Website
urlWebsite = "https://teespring.com/login"
driver.Get urlWebsite
So I have tried to enter my username with the following lines of code:
driver.FindElementByCss("").sendKeys Username
But I got an error saying element not visible
Is there any way I can still automate the login process?
thanks for your help and if you need further information I will try my best to as I am still learning how to handle vba selenium :-)
It is not visible because it is inside a form.
You need to access via form:
Option Explicit
Public Sub EnterInfo()
Dim d As WebDriver
Set d = New ChromeDriver
Const URL = "https://teespring.com/login"
With d
.Start "Chrome"
.get URL
With .FindElementByClass("js-email-login-form")
.FindElementByCss("input[name=email]").SendKeys "myEmail"
.FindElementByCss("input[name=password]").SendKeys "myPassWord"
.FindElementByCss("input[type=submit]").Click
End With
Stop '<== Delete me after inspection
.Quit
End With
End Sub

IBM Connections Activities

I need to Export IBM Connections Activity to csv file by VBA. Do you have any experience with this? It can be done manually by clicking on Edit Activity -> Export Activity -> Export
Edited:
Yes, I am using IBM Connections, interacting on web page in a browser. When I used inspect element, I saw that code for export button is this
<input class="lotusBtn" dojoattachpoint="exportAct_AP" value="Export" dojoattachevent="onclick:exporter" type="button">
so I tried something like this, but I am not still able to fully identify click action:
Sub IEACObject2()
Dim i As Long
Dim objCollection As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://w3-connections.ibm.com/activities/service/html/mainpage#activitypage,25e2e3b1-c4e9-4448-95ae-b72432871095"
Do While IE.Busy
DoEvents
Loop
Set objCollection = IE.Document.getElementsByTagName("input")
i = 0
While i < objCollection.Length
If (objCollection(i).Type = "button" And objCollection(i).Value = "Export") Then
objCollection(i).Click
End If
i = i + 1
Wend
Set IE = Nothing
End Sub
there are API's available.
On Premises : https://www-10.lotus.com/ldd/lcwiki.nsf/xpAPIViewer.xsp?lookupName=IBM+Connections+5.5+API+Documentation
Cloud: https://www-10.lotus.com/ldd/appdevwiki.nsf
You should be able to find all the infos there.....
Maybe use the atom feed (XML) : https://YOUR-CONNECTIONS-SERVER/activities/service/atom2/descendants?nodeUuid=YOUR-ACTIVITY-UID
There is a button for this feed in every activity
I am sure VBA is able to deal with (atom) XML

How to login to a website using vba?

I am trying to login the mentioned website using vba but unable to get through.kindly assist. The website i am trying to logging contains a form where we are suppose to fill our credentials.though, the website is opening using the below enlisted code but nothing happens post that.
Dim HTMLDoc as HTMLDocument
Dim My Browser as Internet Explorer
Sub MYRED()
Dim MyHTML_Element As IHTMLElement
Dim MyURL as String
On Error GoTo Err_Clear
MyURL = "https://www.Markit.com"
Set MyBrowser = New InternetExplorerMedium
MyBrowser.Silent = True
MyBrowser.navigate MyURL`enter code here`
MyBrowser. Visible = True`enter code here`
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser. Document
'Useridele = "input_5ac52c16-cbba-4fb4-b284-857fac1f55fd"
MyBrowser.document.getElementById ("input_5ac52c16-cbba-4fb4-b284- 857fac1f55fd").Value = "user#example.com"
'HTMLDoc.all.input_5ac52c16-cbba-4fb4-b284-857fac1f55fd.Value = "atul.sanwal#markit.com" 'Enter your email id here
passele = "input_b14b8d03-75b6-49b5-a61a-602672036046"
MyBrowser.document.getElementById("input_b14b8d03-75b6-49b5-a61a- 602672036046").Value = "***************"
'HTMLDoc.all.passele.Value = "12345678" 'Enter your password here
For Each My Html_Element in HTMLDoc.getElementsByTagName("input")
If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
Next
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
As I can see this:
"input_5ac52c16-cbba-4fb4-b284-857fac1f55fd")
I'm guessing that this ID is generated every time you are making request
(yep, everytime I'm refreshing this site this element got new ID ), so
You cannot pass static ID as key to get elementById You should try other options to get this specific element You want to fill with data.
Maybe Your library supports gettibng by attribute so, You can get element with atribute
name='username'
One additional proposition :
You are using html to make request via web Interface, but You could try to ommit loging in just to make pure requests.
As I see when filling data and pushing Submit my browser is sending
POST request :
POST /home/UFEExternalSignOnServlet HTTP/1.1
Host: products.markit.com
I dont know how large is your knowledge about WebAPI and etc. but You can write to me if need more help