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

  • Home
  • SEARCH
  • 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 9176773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:11:04+00:00 2026-06-17T17:11:04+00:00

I need to pass arguments to a Excel VBA code from JavaScript of HTA.

  • 0
  1. I need to pass arguments to a Excel VBA code from JavaScript of HTA.

    1. I can successfully call VBA function, but unable to pass string arguments correctly.
    2. JavaScript function can pass different string arguments.
    3. Below is code in simple and demo form.
    4. Excel-VBA code

    Sub subTest(strName As String)
    MsgBox strName
    End Sub
    

HTA code with Javascript

<!DOCTYPE html>
<html>
<head>
<title>HTA</title>
<hta:application 
id="oHta"
applicationname="htaNavi"
border="1"
borderstyle = normal
contextmenu = "yes"
caption="Navigator"
sysmenu="yes"
WINDOWSTATE="maximize"
>
</head>
<body>
<input type="button" value="testing" onclick="funRun('testng string')" />
<input type="button" value="testing second" onclick="funRun('testng')" />
</body>

<script>

var objExl;
var objWb;
var objExl =new ActiveXObject("Excel.Application");
objExl.Visible = true;
var objWb = objExl.Workbooks;
var strpath = '\path\testing_excel_web.xls';
objWb.Open(strpath);

function funRun(strName)
{
alert(strName);
objWb.Application.Run('testing_excel_web.xls!subTest(strName)');
}
</script>
</html>

I can call subTest, but message box populates strName as string but not 'testing string' as text.

  • 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-06-17T17:11:05+00:00Added an answer on June 17, 2026 at 5:11 pm

    I’m thinking you want:

    objWb.Application.Run('testing_excel_web.xls!subTest("' + strName + '")');
    

    This way, the value of the variable strName is concatenated to the command you are attempting to run.

    I know nothing about this calling of a VBA function, so I’m not sure if you need the " around the strName like I provided or not.

    In addition, to be safe, in case your strName value contains ", you should use this:

    objWb.Application.Run('testing_excel_web.xls!subTest("' + strName.replace(/"/g, "\"") + '")');
    

    Hopefully with this, the value of strName could be

    The word "testing" here
    or
    "Here's a quote"
    

    and it will still work.

    The point is that if the string contains ", the Javascript would/could fail. If it would absolutely never contain ", then forget about it. But I think it’s needed since any " in the value of strName will break the passing of it as a parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to call a method from within a function, so I must pass
I need to call a stored procedure and pass arguments in from Powershell. I
I need to pass multiple arguments to a function that I would like to
I have a trigger in SQL Server, but I need to pass arguments to
I need to pass 4 arguments (3 strings and one comma separated list) from
I need to pass arguments onto a callback function as real arguments. How do
how do i pass arguments to generic handler (Asp.net) from javascript/jquery? i have a
In PHP I need to pass some arguments to a function by reference .
How can I bind arguments to a Python function so that I can call
I need to pass an extra parameter :mobilejs => true from jQuery to a

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.