+ Reply to Thread
Results 1 to 2 of 2

Dynamically generated Shell command

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-05-2015
    Location
    czech
    MS-Off Ver
    2010
    Posts
    172

    Dynamically generated Shell command

    Hello, I would like to run dynamically generated Shell commad. The Shell command looks like this:
    Shell "wscript somepath\script.vbs parametr i", vbNormalFocus

    I would like to run this script for sequnce of paramets i like following:

    Sub gen()
    For i=1 To 10
    Shell "wscript somepath\script.vbs parametr i", vbNormalFocus # I know this doesn't work.
    End SubNext i
    I tried to generate sequnce of commands in external txt file. The textfile contains serie of lines bellow, but I don't know how to run it.
    Shell "wscript somepath\script.vbs parametr 1", vbNormalFocus
    Shell "wscript somepath\script.vbs parametr 2", vbNormalFocus
    Shell "wscript somepath\script.vbs parametr 3", vbNormalFocus
    Last edited by jakopak; 02-08-2016 at 10:05 AM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Dynamically generated Shell command

    Hi jakopak,

    The following may help you. I put 4 'double quotes' around each item that may contain an embedded space character.

    Excel Macro Code:
    Sub RunVBS()
    
      Dim sFileName As String
      Dim sPath As String
      Dim sPathAndFileName As String
      Dim p1 As String
      Dim p2 As String
      
      'Get the path
      'Get the File Name
      'Create the full path and file name
      sPath = ThisWorkbook.Path & "\"
      sFileName = "ExcelForumParameterTest.vbs"  'Put your file name here
      sPathAndFileName = sPath & sFileName
      
      'Define the Parameters to pass
      p1 = "abc"
      p2 = "Two Words"
      
      sPathAndFileName = """" & sPathAndFileName & """"
      p1 = """" & p1 & """"
      p2 = """" & p2 & """"
        
      Call Shell("wscript " & sPathAndFileName & " " & p1 & " " & p2, vbNormalFocus)
    
    End Sub
    Wscript Code (my file ExcelForumParameterTest.vbs):
    ' ExcelForumParameterTest.vbs
    ' Reference: http://ss64.com/vb/arguments.html
    wscript.echo "The number of arguments is ", wscript.Arguments.Count
    
    iCount = -1
    For Each strArg in wscript.Arguments
      iCount = iCount + 1
      WScript.Echo "Argument(" & iCount & ") = ", strArg
    Next
    Lewis

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Shell command to rum dos copy command on vba
    By lepmor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2015, 07:04 PM
  2. Dynamically Generated Form And Their Click Events
    By fenilbhoot in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-12-2013, 10:13 AM
  3. [SOLVED] Use VBA to download a dynamically generated image from the web.
    By nponoBegHuk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-01-2012, 09:51 AM
  4. Setting up a dynamically generated range reference
    By cveetan in forum Excel General
    Replies: 8
    Last Post: 02-22-2012, 07:37 AM
  5. Using macro to execute a command in Shell Command
    By aadarsh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-19-2010, 07:06 PM
  6. Get textbox value from custom/dynamically generated form
    By sonyidicula in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-16-2010, 08:52 AM
  7. Dynamically Generated Range using Macro
    By JM.EE01@gmail.com in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-15-2006, 03:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1