VBA getting data seen in Javascript tooltip - javascript

I am trying to extract the data that a javascript tooltip displays, but have no idea how to do it. I thought maybe an XMLHTTP request needs to be sent to the server, but honestly I am not sure. Below is the JS tooltip code to show and hide the tool tip. Is there something else I have to look for other than this to help me get the information that the tooltip shows and put that data in an excel sheet? I really would like some help from beginning to end on this, because I honestly do not know how to start it. Thank you very much.
< a href="javascript:gotopage('D35555')" on mouse over="ajax_showTooltip('D35555','DATA_PAGE',this);return false" on mouse out="ajax_hideTooltip()" >
Here is a link below to Mr. Excel, that I posted the question on, but I do no think they understand what I am trying to do. Thank you
http://www.mrexcel.com/forum/excel-questions/827332-parsing-javascript-%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A-text.html

Try something like that to read parent file
Function GetHTML(URL As String) As String
Dim HTML As String
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", URL, False
.Send
GetHTML = .ResponseText
End With
End Function
From Reading HTML file in VBA Excel
Then find anchor tags as shown in code below
Private Sub SomeMethod()
Dim URL As String, Result As String
URL = "http://localhost/ajax-tooltip/ajax-tooltip.html"
Result = GetHTML(URL)
Dim Document As Object
Set Document = New HTMLDocument
Dim HTMLElement As IHTMLElement
Document.Open
Document.write Result
Document.Close
Dim ElementCollection As IHTMLElementCollection
Set ElementCollection = Document.getElementsByTagName("a")
Dim mouseOverValue As String
For Each HTMLElement In ElementCollection
If Not IsNull(HTMLElement.getAttribute("onmouseover")) Then
mouseOverValue = HTMLElement.getAttribute("onmouseover")
If InStr(mouseOverValue, "ajax_showTooltip") Then
MsgBox ("Find your page here and read its HTML: " + mouseOverValue)
End If
End If
Next HTMLElement
End Sub
Parse mouseOverValue to get value of tooltip page and call GetHTML again for tooltip page

Related

Why Document properties body value is null in lotus notes?

Body content is null in document properties showing this sign ""[] instead of content.
Also messsage box lotus script is showing null with getItemValue("Body").
How to resolve this ?
Sub Click(Source As Button)
Dim s As NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim col As NotesDocumentCollection
Set s = New NotesSession
Set db = s.CurrentDatabase
Set col = db.UnprocessedDocuments
Print "Collection Size:"& col.Count
Set doc = col.GetFirstDocument
If doc.HasItem("Body") Then
While Not doc Is Nothing
Dim body As Variant
body = doc.GetItemValue("Body")
Msgbox (body(0))
Set doc = col.GetNextDocument(doc)
Wend
End If
End Sub
Because (usually) Body is a Rich Text field, and these fields are treated differently. See the NotesRichTextItem in the Designer Help.
Starting from your code:
Set s = New NotesSession
Set db = s.CurrentDatabase
Set col = db.UnprocessedDocuments
Print "Collection Size:"& col.Count
Set doc = col.GetFirstDocument
While Not doc Is Nothing
Dim body As Variant
If doc.HasItem("Body") Then
Set body = doc.GetFirstItem("Body") ' now body contains the richtext item'
Msgbox body.UnformattedText
End If
Set doc = col.GetNextDocument(doc)
Wend
Notes should convert the MIME item to rich text for you. If you want to deal with the MIME type, you have to use the NotesMimeHeader and NotesMimeEntity classes. See the Help database, especially the examples on these classes are interesting.
You cannot just reference a NotesRichtTextItem the same way you reference an ordinary NotesItem. A rich text field can contain graphics, tables, fonts, colors, and other things that are not text. It does not matter if it actually does contain those things; it is never a simple array of strings, so Body(0) is not defined. Look up the methods of the NotesRichTextItem class. You will find one called getUnformattedText which will return a simple text representation of the field value.
(There are options for getting the field value as HTML so that you get all the formatting tags, too, but only if the field is really stored as MIME instead of Notes rich text.)

Click on Href link through vba

I am trying to create IEautomation through vba-excel for the following link.
URL: http://qpldocs.dla.mil/search/default.aspx
The code includes search for the string "QPL-631",and click on the corresponding java script link MIL-I-631D(6).When I inspected "MIL-I-631D(6)" link ,I found following source code of href tag
MIL-I-631D(6)
So there are no click options for the href link and the address of manual clicking on href link is completely different than href address.So I am stuck here.I would like to add a code that clicks "MIL-I-631D(6)" and outputs the results.
I have tried the below code and so far and unable to proceed further.
Private Sub IE_Autiomation()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim ae As HTMLLinkElement
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "http://qpldocs.dla.mil/search/default.aspx"
Application.StatusBar = "Loading. Please wait..."
Do While IE.Busy = True Or IE.readyState <> 4: DoEvents: Loop
Application.StatusBar = "Search form submission. Please wait..."
IE.document.getElementById("Search_panel1_tbox").Value = "QPL-631"
IE.document.getElementById("Search_panel1_btn").Click
Do While IE.Busy = True Or IE.readyState <> 4: DoEvents: Loop
Here is an interim solution to write out to sheet as you are already hard coding the product code "QPL-631" you can just skip straight to using that in the URL string to return your results.
Note: I have pulled the table ID from that page:
html.getElementById("Lu_gov_DG")
You might want to explore if this is a common theme across products (I suspect yes). Will make life a lot easier. You could even do away with IE altogether and go for a faster XHR solution.
Option Explicit
Private Sub IE_Automation()
'References Internet Controls and HTML Object library
Dim i As Long
Dim IE As Object
Dim html As HTMLDocument
Dim product As String
product = "QPL-631"
Dim url As String
url = "http://qpldocs.dla.mil/search/parts.aspx?qpl=1528&param=" & product & "&type=256"
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate url '"http://qpldocs.dla.mil/search/default.aspx"
Application.StatusBar = "Loading. Please wait..."
Do While .Busy = True Or .readyState <> 4: DoEvents: Loop
Set html = .Document
Dim allRowOfData As Object
Set allRowOfData = html.getElementById("Lu_gov_DG")
Dim r As Long, c As Long
Dim curHTMLRow As Object
For r = 1 To allRowOfData.Rows.Length - 1
Set curHTMLRow = allRowOfData.Rows(r)
For c = 0 To curHTMLRow.Cells.Length - 1
Cells(r + 1, c + 1) = curHTMLRow.Cells(c).innerText
Next c
Next r
.Quit
End With
Application.StatusBar = False 'And tidy up our change to the status bar
End Sub
There is example with postback here, which I will have a look at.
Reference:
How to reset the Application.StatusBar
You have several options available to you. See below for a pretty comprehensive list of possibilities.
Try getting the collection of anchor tags, with:
GetElementsByTagName("a")
Then, iterate that collection using as much logic as you can to ensure you're clicking the right button.
For each l in ie.document.getElementsByTagName("a")
If l.ClassName = "hqt_button" Then
l.Click
Exit For
Next
If there are multiple anchors with the same classname, you could do:
If l.ClassName = "hqt_button" AND l.Href = ""javascript:void(0): onclick=HeaderBox.trySubmit()" Then
l.Click
Exit For
Next
Alternatively
If you are using IE9+ you could use the GetElementsByClassName method.
GetElementsByClassName("hqt_button")
How do I use excel vba to click a link on a web page

Adding custom pdf stamp to document from VBA

I've ran into a problem - I need to add a custom stamp (type of annotation) to a number of .pdf files. I can do it through Actions for Acrobat X Pro, but my clients do not have that license and they still need to do it. The list of files is stored in Excel spreadsheet, so ideally I am looking for a VBA solution. I have came up with the following code :
Option Explicit
Sub code1()
Dim app As Acrobat.AcroApp
Dim pdDoc As Acrobat.CAcroPDDoc
Dim page As Acrobat.CAcroPDPage
Dim recter(3) As Integer 'Array defining the rectangle of the stamp - in real code wil be calculated, simplified for ease of reading
Dim jso As Object
Dim annot As Object
Dim props As Object
Set pdDoc = Nothing
Set app = CreateObject("AcroExch.App")
Set pdDoc = CreateObject("AcroExch.PDDoc")
recter(0) = 100
recter(1) = 100
recter(2) = 350
recter(3) = 350
pdDoc.Open ("C:\Users\maxim_s\Desktop\Code_1\test1.pdf")
Set jso = pdDoc.GetJSObject
If Not jso Is Nothing Then
Set page = pdDoc.AcquirePage(0)
Set annot = jso.AddAnnot
Set props = annot.getprops
props.page = 0
props.Type = "Stamp"
props.AP = "#eIXuM60ZXCv0sI-vxFqvlD" 'this line throws an error. The string is correct name of the stamp I want to add
props.rect = recter
annot.setProps props
If pdDoc.Save(PDSaveFull, "C:\Users\maxim_s\Desktop\Code_1\test123.pdf") = False Then
MsgBox "fail"
pdDoc.Close
Else
MsgBox "success"
pdDoc.Close
End If
End If
End Sub
The problem is with the setprops and getprops procedures - it seems that at the moment when annotation is created (jso.AddAnnot) it does not posses the AP property, which is the name of the stamp I want to add. If I set the property Type= "Stamp" first and then try to specify the AP, the result is that one of the default stamps is added and it's AP is renamed to my custom stamps' AP. Also note, that if I launch acrobat and use the code below, the proper stamp is added:
this.addAnnot({page:0,type:"Stamp",rect:[100,100,350,350],AP:"#eIXuM60ZXCv0sI-vxFqvlD"})
If there is a way to execute this Javascript from VBA inside of the PDDoc object, that will solve the problem, but so far I have failed.
You can use "ExecuteThisJavaScript" from the AForm Api. Short example:
Set AForm = CreateObject("AFormAut.App")
AForm.Fields.ExecuteThisJavaScript "var x = this.numPages; app.alert(x);"
It has the advantage that you don't need to translate the js examples into jso code. If you search for ExecuteThisJavaScript you will get some more and longer examples.
Good luck, reinhard
In...
props.Type = "Stamp"
The type should be lower case. But if the pure JavaScript is working from the console, you might consider just executing the string using the jso.

VBA To Extract HTML CDATA

I am trying to use Excel VBA to copy the URL content in between the CData nodes from a list of websites with the same html format. The HTML sample is here:
<script>
//<![CDATA[
Wistia.iframeInit({"assets":[{"type":"original","slug":"original","display_name":
"Original file","ext":"mp4","size":2,"bitrate":2677,"public":true,
"url":"https://embed-ssl.wistia.com/deliveries/1.bin"},
{"type":"original","slug":"original","display_name":"Original file",
"ext":"mp4","size":1,"bitrate":2677,"public":true,
"url":"https://embed-ssl.wistia.com/deliveries/2.bin"},
//]]>
</script>
I am unable to extract the CDATA information with excel VBA alone it seems. Each time I use the following script below, I obtain either blank or "[object HTMLScriptElement]"
Sub test()
Dim ie As Object
Dim html As Object
Dim mylinks As Object
Dim link As Object
Dim lastRow As Integer
Dim myURL As String
Dim erow As Long
Set ie = CreateObject("InternetExplorer.Application")
lastRow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lastRow
myURL = Sheet1.Cells(i, "A").Value
ie.navigate myURL
ie.Visible = False
While ie.readyState <> 4
DoEvents
Wend
Set html = ie.document
Set mylinks = html.getElementsByName("script")(1).innerText
For Each link In mylinks
erow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1).Value = link
Cells(erow, 1).Columns.AutoFit
Next
End Sub
As of my experiences, automating the Internet Explorer is highly unstable. So I would use XMLHTTP as long as possible. Of course your HTML tag soup is not XML and cannot be parsed as such. But we can at least get the responseText with XMLHTTP and then using text methods further.
Example:
Sub test()
sURL = "https://fast.wistia.net/embed/iframe/vud7ff4i6w"
Dim oXMLHTTP As Object
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", sURL, False
oXMLHTTP.Send
sResponseText = oXMLHTTP.responseText
aScriptParts = Split(sResponseText, "<script", , vbTextCompare) 'separate in parts delimited with <script
For i = LBound(aScriptParts) + 1 To UBound(aScriptParts) 'lbound+1 because the first part should not be script. It is the body html.
sScriptPart = Split(aScriptParts(i), "</script", , vbTextCompare)(0) 'only the part before </script belongs to the script
MsgBox sScriptPart
Next
End Sub
You could also use regular expressions instead of the Split approach to separate the script parts from the whole text. But this you should ask the RegEx specialists with a separate question then. I'm not such a RegEx specialist.

How to use asp vbscript to add string items into a javascript array

According to jquery ui API, the source of an autocomplete field may be an array variable. How can I populate the array variable with results from a vbscript recordset result?
In the body of my page the I have my code something like this:
Dim rs, data_source
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_rtasql_STRING
rs.CursorType = 2
rs.CursorLocation = 2
rs.LockType = 3
rs.source = "select field1 from mydatabase where whatever > soandso"
WHILE NOT rs.EOF
//add each result to string array JavaScript/Jquery can access.
I would like to pull the variable in my document ready function for my jquery auto complete field. How can this be implemented?
Thank You.
http://jqueryui.com/autocomplete/#remote the remote datasource. When using firefox with firebug I press F12 to open the console and see the xhr request made when I type something.
Inspecting the response I can see that JSON is used:
[{"id":"Turdus philomelos","label":"Song Thrush","value":"Song Thrush"},
{"id":"Melospiza melodia","label":"Song Sparrow","value":"Song Sparrow"}
]
I think you can leave out the id because that would be optional. You could try an array of strings return like:
["Song Thrush","Song Sparrow"]
The vb code you're showing looks like server side code that would not run in a browser, the autocomplete will make a call to that asp page when the user types something and that is then used to filter your data:
The GET parameter that the autocomplete sends is called term. Look for the js code on the jquery ui page: http://jqueryui.com/autocomplete/#remote
You could do something like this, assuming that you are happy populating the list on page load and don't want to do a lookup to the server in real-time:
<%
' server-side ASP
Dim rs, data_source, ado
Set ado = CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
ado.ConnectionString = MM_rtasql_STRING
ado.Open
rs.ActiveConnection = ado
rs.CursorType = 2
rs.CursorLocation = 2
rs.LockType = 3
rs.Open "select field1 from mydatabase where whatever > soandso"
' build up a string which looks like a Javascipt array (eg "['val1','val2']")
' instead of a loop, you could use rs.GetString(), which is quicker
dim s: s = "["
do until rs.EOF
s = s & "'" & CStr(rs("field1")) & "',"
loop
rs.Close
' remove trailing comma and complete array string
s = left(s, len(s) - 1) & "]"
%>
<!-- client-side -->
<script type="text/javascript">
$(document).ready(function() {
$("textbox-selector").autocomplete({
source: <%=s %> // ASP insert of javascript array string
});
});
</script>
I've not tested this and the jQuery I've taken from their example: http://jqueryui.com/autocomplete/
How about using the push() method?

Categories

Resources