473,699 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

execute javascript on a webpage via VBA

5 New Member
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.
Aug 19 '13 #1
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
Aug 19 '13 #2
LWKnox
5 New Member
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command292_Click()
  2. Dim StrWebpage As String
  3. StrWebpage = "http://exclusions.oig.hhs.gov/Default.aspx"
  4.  
  5.     Dim objIE As SHDocVw.InternetExplorer 'microsoft internet controls (shdocvw.dll)
  6.     Dim HTMLDoc As MSHTML.HTMLDocument 'Microsoft HTML Object Library
  7.     Dim htmlInput As MSHTML.HTMLInputElement
  8.     Dim htmlColl As MSHTML.IHTMLElementCollection
  9.      'Dim HTMLImage As MSHTML.IHTMLInputImage
  10.  
  11.  
  12.     Set objIE = New SHDocVw.InternetExplorer
  13.  
  14.        With objIE
  15.          .navigate StrWebpage ' Main page
  16.          .Visible = 1
  17.          Do While .Busy: DoEvents:   Loop
  18.  
  19.  Do While .ReadyState <> 4: DoEvents: Loop
  20.  
  21.  Set HTMLDoc = .Document
  22.  Set htmlColl = HTMLDoc.getElementsByTagName("Image")
  23.  Set objIE = New SHDocVw.InternetExplorer
  24.   Call objIE.Document.Frames(1).Document.parentWindow.execScript("javascript:_doPostBack('ctl00$cpExclusions$lbSearchMP','')")
  25.   end with
  26. end sub
Here is part of the source code:
Expand|Select|Wrap|Line Numbers
  1. For Multiple Individuals" style="border-width:0px;" />
  2.             <a id="ctl00_cpExclusions_lbSearchMP" href="javascript:__doPostBack('ctl00$cpExclusions$lbSearchMP','')">Search For Multiple Individuals</a> &nbsp;&nbsp; |
Aug 19 '13 #3
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.
Aug 19 '13 #4
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
Aug 19 '13 #5
LWKnox
5 New Member
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.
Aug 19 '13 #6
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."
Aug 19 '13 #7
LWKnox
5 New Member
Should ("PressThisHere Button()") be 'ctl00$cpExclus ions$lbSearchMP '?
Aug 19 '13 #8
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.
Aug 19 '13 #9
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.}
Expand|Select|Wrap|Line Numbers
  1. Sub IE_Run_Google()
  2.     '
  3.     'based on: http://vba-corner.livejournal.com/4623.html.
  4.     '
  5.     On Error GoTo errorjumppoint
  6.     Dim z_ie As InternetExplorer
  7.     '
  8.     Set z_ie = New InternetExplorer
  9.     '
  10.     z_ie.Navigate "www.google.com"
  11.      'Loop until it has loaded.
  12.     Do Until z_ie.ReadyState = READYSTATE_COMPLETE
  13.     Loop
  14.     '
  15.     z_ie.Visible = True
  16.     z_ie.Document.getElementById("q").Value = "VBA Example"
  17.     z_ie.Document.getElementById("q").Click
  18.     z_ie.Document.getElementById("btnK").Click
  19.     '
  20. errorjumpreturn:
  21.     If Not z_ie Is Nothing Then Set z_ie = Nothing
  22.     '
  23. Exit Sub
  24. errorjumppoint:
  25.     MsgBox "Somethin went wrong:" & Err.Number & vbCrLf & Err.Description
  26.     Resume errorjumpreturn
  27. 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!
Aug 19 '13 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6402
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
2
4303
by: jm | last post by:
I have a parent window: <script language="javascript"> function doSearch() { result=showModalDialog("searchmni.aspx?lastname=smith"); alert(result); } </script>
2
5584
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")%>...
5
4929
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?
1
1961
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.
1
9706
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
4
4062
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: ...
11
9414
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)
1
10284
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
7
4487
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...
0
8704
marktang
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...
0
8894
tracyyun
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...
0
7777
agi2029
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...
1
6544
isladogs
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...
0
5879
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();...
0
4390
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...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
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
2
2361
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.