简体   繁体   中英

Website Message Box by Automating InternetExplorer with VBA Excel

I am in the process of automating a process to fill up a website. With an Excel Macro, once I log into the website, insert a value in the required textbox and click the button, a website Message Box comes up with an alert asking me to confirm - Are you sure to update the value?

The execution of the macro stops at that level, resulting in no further execution of the macro.

On searching for the solution, I found out that a JavaScript function, the function which is executed on confirmation of the message box, should be called from macro instead of clicking the original button on the webpage.

I would like to have help in writing the code to call JavaScript function in Excel Macro.

Following is the HTML code from the view source page of the webpage.

$('#reloadButton').click(function () {
    $(this).text(
        $(this).attr('name')
    ).attr('disabled', 'disabled');

    window.location.href = window.location.href.replace(/#.*$/, '');
});

SignalConsumer = function () {};

SignalConsumer.prototype = new TraderSettingsTool();

SignalConsumer.prototype.mySummaryPage = 'https://kvinvest.com/month/?action=template&tid=my_status';

SignalConsumer.prototype.isShowWaiver = 0;

SignalConsumer.prototype.amountPrecision = 1;



SignalConsumer.prototype._elements = {
    "trading": {
        "popup": $('#ssc-trading-popup'),
        "amount": $('#ssc-trading-amount'),
        "trade": $('#ssc-trading-trade'),
        "provides": $('#ssc-trading-provides')
    },
    "slippage": {
        "popup": $('#ssc-slippage-popup')
    },
    "provider": {
        "popup": $('#ssc-provider-popup')
    },
    "consumers":{
       "holder":   $('#ssc-consumers-holder'),
       "template": $('#ssc-consumers-template'),
       "form":     $('#ssc-consumers-form')
    },
    "subscribe": {
        "server": $('#ssc-subscribe-server'),
        "apply":  $('#ssc-subscribe-apply'),
        "loader": $('#ssc-subscribe-loader'),
        "info":   $('#ssc-subscribe-info'),
        "form":   $('#ssc-subscribe-form'),
        "description":   $('#ssc-subscribe-description')
    },
    "activate": {
        "form": $('#ssc-activate-form'),
        "slippage": $('#ssc-activate-slippage'),
        "amount": $('#ssc-activate-amount'),
        "popup": $('#ssc-activate-popup'),
        "apply": $('#ssc-activate-apply'),
        "cancel": $('#ssc-activate-cancel'),
        "agree": $('#ssc-activate-agree'),
        "sll": $('#ssc-activate-sll-value'),
        "loader": $('#ssc-activate-sll-loader'),
        "redirect": $('#ssc-activate-redirect')
    },
    "waiver": {
        "popup": $('#ssc-waiver-popup'),
        "agree": $('#ssc-waiver-agree'),
        "apply": $('#ssc-waiver-apply'),
        "subscribe": $('#ssc-waiver-subscribe')
    },
    "history": {
        "log": $('#ssc-history-log')
    }
};

SignalConsumer.prototype.bindEvents = function () {
    var self = this;

    this._elements.subscribe.form.find('form').submit(function () {
        return false;
    });


      // I THINK BELOW IS THE MESSAGE BOX POP UP

    this._elements.subscribe.apply.click(function () {

        if(!confirm('Are you sure to update?')){
            return false;
        }

        self.subscribeToServer();
        return false;
    });

    // On show history popup
    this._elements.history.log.click(function () {
        self.loadHistoryLog();
        return false;
    });

    // --- ACTIVATION LOGIC ---
    this._elements.activate.apply.click(function () {
        self.applyActivateServer();
        return false;
    });

    this._elements.activate.agree.change(function () {

        var disabled = $(this).is(':checked') ? '' : 'disabled';

        self._elements.activate.apply.attr('disabled', disabled);
    });

    this._elements.activate.cancel.click(function () {
        self.hidePopUp();
        return false;
    });

    this._elements.activate.redirect.click(function () {
        self.hidePopUp();
    });

Well, what I won't do in this answer is provide the code that you request.
This answer is more like a suggestion since I'm not entirely sure about where you are going with this and if the technical approach that you suggest is what you are actually looking for.

It doesn't make a lot of sense to me, to connect the VBA engine with a web client unless you're aiming at retrieval of data only - such as for example a web query.
If you want to create an interactive data flow between the VBA engine and a web application, it seems more logical to create a connection with a server side script (written in PHP or ASP) that is connected to a database system (or if you want to store values in temporary session variables for that matter).

The fact that a user inputs a value, followed by a button click suggests that you want to build in a certain calculation logic. This is typically done on the server, and not browser level.

Therefore what I suggest you do is:

Javascript/jQuery -> PHP/ASP -> VBA 

If that makes any sense to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM