Solved

Need VBA code to execute JavaScript.

Posted on 2008-09-29
8
1,768 Views
Last Modified: 2013-12-08
Hi All,

I need VBA to execute JavaScript.  The website I am working on has you put in an account number, then it asks you to click a link called view my account.  I have written code to input the account number, but the code that I wrote to click the link does not work properly.  I clicks the link, but evidently does not run the javascript.  I know this because it tells me the account number is invalid.  The source code for the link is below.

<a href="javascript:CheckAndSubmit( document.frmViewMyAcct )">View My Account</a><br>

The code that I have that clicks the clink is:

IE.document.frmviewmyacct.submit

Which I know is incorrect.

Any help would be greatly appreciated.  Thanks in advance.



0
Comment
Question by:g8rbroker
  • 4
  • 4
8 Comments
 
LVL 50

Expert Comment

by:Dave Brett
ID: 22599800
Hi,

You can use execScript in VBA to control the Java, for example see http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21057068.html

Cheers

Dave
0
 

Author Comment

by:g8rbroker
ID: 22599856
Thanks for the response,

I tried writing the following:

Call IE.document.execScript("checkandsubmit(document.frmviewmyacct);", "JavaScript")

However, I got the error message below:

Run-time error '438':
Object doesn't support this property or method

Did I write this wrong? or am I possibly missing a reference?  I am currently using Microsoft Internet Controls and Microsoft HTML Objects Library

Thanks.
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 22599943
I assume there is no issue with you posting a link to the site ?

Cheers

Dave
0
 

Author Comment

by:g8rbroker
ID: 22600013
I know this may make it more difficult, but I can't post the site.  It is for a vendor of my company.  Even if I could, you would need an account number to see if it could work anyway.  As you could assume, I deffinately can't post that.  Sorry for making this harder than it needs to be.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 50

Accepted Solution

by:
Dave Brett earned 500 total points
ID: 22600093
Ok - Understood. I don't think we need an account though, any text would do just to test if the button was being run

Do you get any joy by looping through the frames?

Cheers

Dave
 On Error Resume Next

 For i = 0 To myIE.Document.frames.length - 1

    Call IE.Document.frames(i).execscript("checkandsubmit(document.frmviewmyacct);", "JavaScript")

    if err.number = 0 then

         exit for

    end if

 Next

 On Error Goto 0

Open in new window

0
 

Author Comment

by:g8rbroker
ID: 22613865
Thanks for the help.  I found that the following code works:

IE.document.parentWindow.execScript "CheckAndSubmit(document.frmViewMyAcct);"

0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 22632324
No probs, glad to have helped

Cheers

Dave
0
 

Author Closing Comment

by:g8rbroker
ID: 31502733
This was not exactly the correct answer, but it pointed me in the direction that I needed.  Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Secure Connection Failed - Sonicwall FW 1 50
Help with Adding text from a form to a worksheet 5 36
Excel Score Formula 5 46
Chrome SSRS print Functionality 1 17
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now