RE: execute javascript on a webpage via VBA
I have a procedure that opens a webpage. What I want to do is click a button on that page, but it isn't really a button. There is a Javascript function that clicking the "button" runs to open a different version of the webpage.
12 23812 jimatqsi 1,276
Recognized Expert Top Contributor
This is in the VBA forum. I think you actually want to post that elsewhere. Either in the. .Net forum or javascript forum.
That being said, here's documentation on opening a URL in javascript. http://www.w3schools.com/jsref/met_win_open.asp
Jim
- Private Sub Command292_Click()
-
Dim StrWebpage As String
-
StrWebpage = "http://exclusions.oig.hhs.gov/Default.aspx"
-
-
Dim objIE As SHDocVw.InternetExplorer 'microsoft internet controls (shdocvw.dll)
-
Dim HTMLDoc As MSHTML.HTMLDocument 'Microsoft HTML Object Library
-
Dim htmlInput As MSHTML.HTMLInputElement
-
Dim htmlColl As MSHTML.IHTMLElementCollection
-
'Dim HTMLImage As MSHTML.IHTMLInputImage
-
-
-
Set objIE = New SHDocVw.InternetExplorer
-
-
With objIE
-
.navigate StrWebpage ' Main page
-
.Visible = 1
-
Do While .Busy: DoEvents: Loop
-
-
Do While .ReadyState <> 4: DoEvents: Loop
-
-
Set HTMLDoc = .Document
-
Set htmlColl = HTMLDoc.getElementsByTagName("Image")
-
Set objIE = New SHDocVw.InternetExplorer
-
Call objIE.Document.Frames(1).Document.parentWindow.execScript("javascript:_doPostBack('ctl00$cpExclusions$lbSearchMP','')")
-
end with
-
end sub
Here is part of the source code: - For Multiple Individuals" style="border-width:0px;" />
-
<a id="ctl00_cpExclusions_lbSearchMP" href="javascript:__doPostBack('ctl00$cpExclusions$lbSearchMP','')">Search For Multiple Individuals</a> |
zmbd 5,501
Recognized Expert Moderator Expert
jimatqsi:
I moved the question from the title to the body of the text. This helps to clarify that the topic concerns VBA.
LWKnox:
We will need to see the code that you are using to call the webpage so that one of the experts here can determine how best to get the "handle" to the open webpage.
jimatqsi 1,276
Recognized Expert Top Contributor
So you don't actually turn control over the browser in this case? I didn't know you could do that. This could very useful. Thanks, zmbd.
jim
The VBA code here is just a small part of a larger, more ambitious effort. When I can get the page with fields for multiple persons open, I will make it enter into those spaces names I have on the Access form and click the search button. This is just a first step.
zmbd 5,501
Recognized Expert Moderator Expert
LWKnox:
Line 24 of your code appears to be malformed; however, honestly, I've never attempted this so I could be very mistaken.
Double check that the reference to the frame is correct. If the control is in a different frame or if there are no frame then you call will more than likely fail. I don't know if it will error. execScript("jav ascript:_doPost Back('ctl00$cpE xclusions$lbSea rchMP','')")
is the part that I think may be your issue.
You need to call the function within the frame so that it looks like: execScript("Pre ssThisHereButto n()", "JavaScript ")
However, please take that with a "grain or two of salt."
Should ("PressThisHere Button()") be 'ctl00$cpExclus ions$lbSearchMP '?
zmbd 5,501
Recognized Expert Moderator Expert
LWKnox
That you will have to try yourself. I have no knowledge of your page design and I'm afraid I just don't have the knowledge to dig thru the java to find what you should place there and what little help from the VBA side that I can offer is based upon the help files for IE-Automation.
You may be able to use a simple "object.cli ck" if you know the element's name.
We'll just have to wait a bit a see if someone with more IE-Automation has something to offer.
zmbd 5,501
Recognized Expert Moderator Expert
jimatqsi
So you don't actually turn control over the browser in this case? I didn't know you could do that. This could very useful. Thanks, zmbd.
jim
Yes, that is what I'm saying.
I ran across the following article awhile back: Working with Internet Explorer Using VBA
using that information, some trial and error with the element id to find the text box, I came up with this just as a proof of concept; however, I couldn't figure out how to get the "enter" or "search" button to trigger - I didn't put a lot of time into it either:
{Note: 2013-08-21-1334CST: The following code was edited to add error trapping and modified to actually run the search.} - Sub IE_Run_Google()
-
'
-
'based on: http://vba-corner.livejournal.com/4623.html.
-
'
-
On Error GoTo errorjumppoint
-
Dim z_ie As InternetExplorer
-
'
-
Set z_ie = New InternetExplorer
-
'
-
z_ie.Navigate "www.google.com"
-
'Loop until it has loaded.
-
Do Until z_ie.ReadyState = READYSTATE_COMPLETE
-
Loop
-
'
-
z_ie.Visible = True
-
z_ie.Document.getElementById("q").Value = "VBA Example"
-
z_ie.Document.getElementById("q").Click
-
z_ie.Document.getElementById("btnK").Click
-
'
-
errorjumpreturn:
-
If Not z_ie Is Nothing Then Set z_ie = Nothing
-
'
-
Exit Sub
-
errorjumppoint:
-
MsgBox "Somethin went wrong:" & Err.Number & vbCrLf & Err.Description
-
Resume errorjumpreturn
-
End Sub
Maybe the journal entry is still available for view!
Appears blocked by my Co-ISP; however, they block about 65% of the web!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: nerf |
last post by:
How can I execute a javascript file(test.js) from within PHP. I'm running
oscommerce and want to insert a menu created in javascript by Sothink
DHTMLMenu. Thanks in advance
|
by: jm |
last post by:
I have a parent window:
<script language="javascript">
function doSearch() {
result=showModalDialog("searchmni.aspx?lastname=smith");
alert(result);
}
</script>
|
by: Dave |
last post by:
Hi,
I have a datagrid with a Templated column below. I want to execute some javascript before the postback to show a hidden "div" tag with static message of "Please Wait..." since the query takes a few seconds. The js function simply sets the css style to display.
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton Runat="server" CommandName="Select" ID="lbtnCompanyName">
<%# DataBinder.Eval(Container.DataItem, "CompanyName")%>...
|
by: Scott Natwick |
last post by:
Is there a way to execute a JavaScript from the Page_Load event?
Or alternatively, is there a way to have it execute when the page is loaded?
I am defining the script in the Page_Load event and using the
RegisterStartupFunction to add it to the page. I just need a way to execute
the script when the page loads.
Any ideas?
|
by: M |
last post by:
Hi everybody,
I have a Web form with something like:
<form id="Form1" method="post" onsubmit="javascript:submitForm();"
runat="server">
I need the JavaScript function submitForm() to execute everytime the form is
submitted.
I also have two RadioButtons with AutoPostBack set to true.
| |
by: Peter Dickson |
last post by:
I am trying to pull data from a website into a database. Part of the
website I am getting the data uses javascript to display the data.
The only variable being passed to the javascript when it is executed is a
record number (Ex: javascipt:getDetails('123456789')
Can VB.Net control execute the javascript? If so, does anyone have an
example of how it can be done.
Thanks
|
by: Ian Kelly |
last post by:
Hi All,
I have an .net form that is split into two frames. The left frame has a
tree that displays a list of all the customers. The right frame displays
the appropriate clients information. When the save button is pressed on the
right frame, I want to update the tree in the left frame AFTER saving all
the data as the changes to the right frame may affect how the tree is
displayed. I tried using the following:
...
|
by: Hakan ÖRNEK |
last post by:
Hi ,
I register client scripts like this;
--------------------------------------------------------------------------
-----------
Public Sub CreateClientAlert(ByVal Message As String, ByVal objPage As
Page)
Dim StrScript As New StringBuilder("")
With StrScript
.Append("<script type=""text/javascript"">")
.Append(vbCrLf)
|
by: Veerle |
last post by:
Hi,
I have a web page and at the end of the page I have inserted some
javascript that checks if Acrobat Reader plugin is installed. If it is
not installed, I disable some elements (buttons, checkboxes, ...) on
the page. This javascript is at the end of the page, because
javascript cannot identify html elements if they are defined below the
script.
Some of the elements that I disable when the plugin is not installed
|
by: Peter |
last post by:
I have a HoverMenuExtender which contains an asp:PlaceHolder, this place
holder has a User Control and this control contrains a Button.
The problem I am having is after the button fires the click event I want to
do a server side function and then refresh the Page where the PlaceHolder
risides.
I have no problem doing the server side function, but the following 'alert'
never shows up after the server side funtion.
I am using the alert...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |