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 6930321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:25:56+00:00 2026-05-27T11:25:56+00:00

I generally use VB.Net for programming but I have been delegated to a VBA

  • 0

I generally use VB.Net for programming but I have been delegated to a VBA project that would benefit from using script control for running script. Here is sample code but errors out on the .Run line of code. I can do this in VB.Net easy but can’t get it to work in vba.

ERROR = Wrong number of arguments or invalid property assignent

Option Explicit
Dim sc As New ScriptControl

Sub RunFunctions()
    MsgBox (Eval("2 * PI"))
End Sub

Function Eval(expr As String) As Object
    Dim code As String
    code = "Dim PI" & vbCrLf & _
           "PI = 3.1416" & vbCrLf & _
           " " & vbCrLf & _
           "Function Result" & vbCrLf & _
           "    Result = " & expr & vbCrLf & _
           "End Function"

    sc.Language = "VBScript"
    sc.AllowUI = True
    sc.AddCode (code)
    Dim myparams() as variant

    Eval = sc.Run("Result", myparams)

End Function

Using the .Eval function from the script control object runs ok in vba but does not run scripts. Here is an example of that if someone cares to know…

Sub SimpleTask()
    Dim expr As String
    sc.Language = "VBScript"
    expr = "2 + 2 * 50"
    MsgBox sc.Eval(expr)
End Sub
  • 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-27T11:25:57+00:00Added an answer on May 27, 2026 at 11:25 am

    Here is the final working code for VBA. competent_tech has one for VB.Net.

    Option Explicit
    Dim sc As New ScriptControl
    
    Sub RunFunctions()
        MsgBox (Eval("2 * PI"))
    End Sub
    
    Function Eval(expr As String) As String
        Dim code As String
        code = "Dim PI" & vbCrLf & _
               "PI = 3.1416" & vbCrLf & _
               " " & vbCrLf & _
               "Function Result" & vbCrLf & _
               "    Result = " & expr & vbCrLf & _
               "End Function"
    
        sc.Language = "VBScript"
        sc.AllowUI = True
        sc.AddCode (code)
    
        Eval = sc.Run("Result")
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using asp.net programming just from few months and I have to
OK, I don't do much .Net programming, but I do have one that I
Generally when I use ClickOnce when I build a VB.NET program but it has
I generally use will_paginate for the pagination in my app, but have hit a
Brief blurb, My skill in .net has been called innovative but I would prefer
How would one use SignalR to implement notifications in an .NET 4.0 system that
It is generally accepted that the use of cursors in stored procedures should be
Every class that wants to use java.util.logging generally needs to declare a logger like
I generally stay away from regular expressions because I seldom find a good use
Many of us have been indoctrinated in using XML for storing data. It's benefits

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.