Need VBA code to execute JavaScript.

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.



g8rbrokerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
DaveConnect With a Mentor Commented:
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
 
DaveCommented:
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
 
g8rbrokerAuthor Commented:
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
DaveCommented:
I assume there is no issue with you posting a link to the site ?

Cheers

Dave
0
 
g8rbrokerAuthor Commented:
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
 
g8rbrokerAuthor Commented:
Thanks for the help.  I found that the following code works:

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

0
 
DaveCommented:
No probs, glad to have helped

Cheers

Dave
0
 
g8rbrokerAuthor Commented:
This was not exactly the correct answer, but it pointed me in the direction that I needed.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.