Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7689941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:16:55+00:00 2026-05-31T20:16:55+00:00

I am trying to change the function call from the onclick event of a

  • 0

I am trying to change the function call from the onclick event of a button on a form using automation in VBA. Function X is already hard-coded into the webpage, and I do not have access to change that code. (The page is internal to my company, but I am not in that department).

When my scenario fits, I want to replace function X with a new function Y.

I’ve seem similar questions to this one SO, but it appears most refer to changing an element attribute from within JS code. My problem is that I need to so this in VBA and I’m not sure how to get there.

This site has a good deal of information regarding this process (setAttribute, getAttribute, etc.), including useful info re: caveats when working with one browser vs. another. All my code will be interfacing with IE (what the company provides), so no need to worry about the other browser options.

When trying to change the onclick attribute, the VBE watch panel shows a change in the attribute, but it does not behave as expected. After I have changed the attribute, nothing at all happens when I click (either through my automation of objButton.Click / objButton.onclick, or actually manually clicking the button). I have also tried this on other attributes (i.e. onfocus) with the same results. The link above mentions IE has some difficulty with this, but I’m not overly familiar with JavaScript and I am having trouble following the guide.

What I have tried is the following, all of which have the same result.

Option 1:

Set TEST = myIEWindow.Document.createattribute("onclick")
TEST.nodevalue = "function anonymous() {alert(""test""); };"
objButton.setAttributeNode TEST

Option 2:

objButton.Attributes("onclick").value = "function anonymous() {alert(""test""); };"

Option 3:

objButton.Attributes("onclick").value = "alert(""test"");"

Option 4:

objButton.setAttribute "onclick", "alert(""test"");"

Option 5:

objButton.onclick = "function() { alert(""test""); };"

While trying these different methods out, I did notice that the onclick attribute type in the VBE watch window changes from its original type of Variant/Object to Variant/String after attempting to coerce the button to call the new function, and I feel this has something to do with my problem.

Can someone please explain how (if possible) I can get this to work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:16:56+00:00Added an answer on May 31, 2026 at 8:16 pm

    You can change this on the element property directly.

    var objButton = document.getElementById("buttonId");
    objButton.onclick = function() { alert("test"); };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to call a javascript function from onClick event of an asp
I'm trying to make my QTableWidget call some function when I change the values
I'm trying to call a function from this: var _coll = [new Obj('a', somefunction)];
I am making ajax call(ASP.NET 3.5) from dropdown change handler and trying to pass
I'm trying to write a jQuery function to change out href of a link,
I'm trying to execute this function when a select list's (LevelId0) value change but
Am trying to change the button frame according to the orientation change but button
I'm getting some weird behavior from IE when trying to change a session variable
What Im Doing: Trying to call Fancybox from an iFrame to be appended to
Is there a way to create a va_list from scratch? I'm trying to call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.