Skip to content Skip to sidebar Skip to footer

Vbscript To Click Link On A Web Page Table That Calls Embedded (?) Javascript Function

At my work we have a very tedious process where we have to pull information from a web database and enter into a word document. Right now, we have no way to query the database and

Solution 1:

Thanks to everyone who helped out. However, for some reason, the above methods didn't work out in this particular webpage. I did, however, find a solution and wanted to post the answer in case it helps anyone else who may be stuck with this issue.

The code to click the requested link is below.

OptionExplicitPublicDeclare PtrSafe Sub Sleep Lib"kernel32" (ByVal dwMilliseconds As LongPtr)

Sub Routine()

Dim IE asObjectSet IE = GetIE

With IE

    .Visible = True
    .Navigate "https://myURL/Default.aspx"

    IEWait

    Dim oDoc asObject, sLink asStringSet oDoc = .document
    sLInk = "in_1191_1"

    IECLickLink oDoc, sLink

EndSubSub IEClickLink(doc AsObject, sLink AsString)
'assumes IE is loaded as InternetExplorer.Application") with URL loaded'assumes doc is declared as IE.documentWith doc

    Dim oLink AsObjectForEach oLink In .Links

        If InStr(1, oLink.href, sLink) Then'looks for particular text in href attribute then clicks that particular link
            oLink.Click
            ExitForEndIfNextEndWithEndSubFunction GetIE() AsObjectOnErrorResumeNextSet GetIE = CreateObject("InternetExplorer.Application")
EndFunctionSub IEWait()
'assumes IE is loaded as InternetExplorer.ApplicationWith IE
    DoWhile .Busy Or .ReadyState <> 4: Sleep (100): LoopEndWithEndSub

Solution 2:

You may also have been able to use a CSS selector of

a[href=javascript:setCursorPosition(1191, 'HATSForm');checkInput2('in_1191_1', '1','hidden');ms('[enter]', 'HATSForm')]

This literally says get the a tag element with href attribute whose value is javascript:setCursorPosition(1191, 'HATSForm');checkInput2('in_1191_1', '1','hidden');ms('[enter]', 'HATSForm'

It would have been applied as:

oDoc.querySelector("a[href=javascript:setCursorPosition(1191, 'HATSForm');checkInput2('in_1191_1', '1','hidden');ms('[enter]', 'HATSForm')]").Click

Solution 3:

You can always use the execScript() function to call a JavaScript function:

IE.document.parentWindow.execScript "ms('[enter]','HATSForm');", "javascript"

Post a Comment for "Vbscript To Click Link On A Web Page Table That Calls Embedded (?) Javascript Function"