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

The Archive Base Latest Questions

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

I need some excel vba examples, where with in the VBA code(Excel Macro) i

  • 0

I need some excel vba examples, where with in the VBA code(Excel Macro) i could call a VBScript and will get some values like filename and directory information from the vbscript and assign it to the variables in VBA code.
Thank you in advance

Some thing like this

VBA macro:

Sub Foo2Script
Dim x As Long
x=2
'Call VBscript here
MsgBox scriptresult
End Sub

VBScript:

Dim x, y ,Z
x = x_from_macro
y = x + 2
Z = X+Y
scriptresult = y,Z
  • 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-22T22:31:17+00:00Added an answer on May 22, 2026 at 10:31 pm

    It can be done but I would have to agree with Tomalak and others that it’s not the best way to go. However, saying that, VBScript can work wonders occasionally if you use it as a kind of fire and forget mechanism. It can be used quite effectively to simulate multi-threading in VBA whereby you breakdown the payload and farm it out to individual VBScripts to run independently. Eg you could arrange a “swarm” of individual VBScripts to mass download from websites in the background whilst VBA continues with other code.

    Below is some VBA code I’ve simplified to show what can be done and writes a simple VBScript on the fly. Normally I prefer to run it using 'wshShell.Run """" & SFilename & """" which means I can forget about it but I’ve included in this example this method Set proc = wshShell.exec(strexec) which allows a test of the object for completion

    Put this in MODULE1

    Option Explicit
    
    Public path As String
    
    Sub writeVBScript()
    Dim s As String, SFilename As String
    Dim intFileNum As Integer, wshShell As Object, proc As Object
    
    
    Dim test1 As String
    Dim test2 As String
    
    test1 = "VBScriptMsg - Test1 is this variable"
    test2 = "VBScriptMsg - Test2 is that variable"
    
        'write VBScript (Writes to Excel Sheet1!A1 & Calls Function Module1.ReturnVBScript)
        s = s & "Set objExcel = GetObject( , ""Excel.Application"") " & vbCrLf
        s = s & "Set objWorkbook = objExcel.Workbooks(""" & ThisWorkbook.Name & """)" & vbCrLf
        s = s & "Set oShell = CreateObject(""WScript.Shell"")" & vbCrLf
        s = s & "Msgbox (""" & test1 & """)" & vbCrLf
        s = s & "Msgbox (""" & test2 & """)" & vbCrLf
        s = s & "Set oFSO = CreateObject(""Scripting.FileSystemObject"")" & vbCrLf
        s = s & "oShell.CurrentDirectory = oFSO.GetParentFolderName(Wscript.ScriptFullName)" & vbCrLf
        s = s & "objWorkbook.sheets(""Sheet1"").Range(""" & "A1" & """) = oShell.CurrentDirectory" & vbCrLf
        s = s & "Set objWMI = objWorkbook.Application.Run(""Module1.ReturnVBScript"", """" & oShell.CurrentDirectory & """")  " & vbCrLf
        s = s & "msgbox(""VBScriptMsg - "" & oShell.CurrentDirectory)" & vbCrLf
        Debug.Print s
    
        ' Write VBScript file to disk
        SFilename = ActiveWorkbook.path & "\TestVBScript.vbs"
        intFileNum = FreeFile
        Open SFilename For Output As intFileNum
        Print #intFileNum, s
        Close intFileNum
        DoEvents
    
        ' Run VBScript file
        Set wshShell = CreateObject("Wscript.Shell")
        Set proc = wshShell.exec("cscript " & SFilename & "") ' run VBScript
        'could also send some variable
        'Set proc = wsh.Exec("cscript VBScript.vbs var1 var2") 'run VBScript passing variables
    
        'Wait for script to end
        Do While proc.Status = 0
        DoEvents
        Loop
    
        MsgBox ("This is in Excel: " & Sheet1.Range("A1"))
        MsgBox ("This passed from VBScript: " & path)
    
        'wshShell.Run """" & SFilename & """"
    
        Kill ActiveWorkbook.path & "\TestVBScript.vbs"
    End Sub
    
    
    Public Function ReturnVBScript(strText As String)
    path = strText
    End Function
    

    This demonstrated several ways that variables can be passed around.

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

Sidebar

Related Questions

Am not that skilled at Excel/VBA and need some help. The code below (in
I need to use VBA to filter some information in excel. As I have
I need to import some Excel spreadsheets into Java objects. I will use POI
I need to generate a file for Excel, some of the values in this
Excel VBA: I am trying to get to some activex option buttons through the
In some VBA attached to an Excel 2003 spreadsheet I need to make use
I need to invoke a VBA macro within an Excel workbook from a python
I have an Excel file that has a bunch of VBA and macro code
I am trying to write some vba code in Excel to query a table
I have an excel file that I need to make some changes. I need

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.