Results 1 to 23 of 23

Thread: Excel: How to: Pass Command Line Parameter [DKenny is KING!]

Threaded View

  1. #3
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Excel: How to: Pass Command Line Parameter ???

    Webtest

    Add a module and insert the following code
    VB Code:
    1. Option Base 0
    2. Option Explicit
    3.  
    4. Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineW" () As Long
    5. Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
    6. Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (MyDest As Any, MySource As Any, ByVal MySize As Long)
    7.  
    8. Function CmdToSTr(Cmd As Long) As String
    9. Dim Buffer() As Byte
    10. Dim StrLen As Long
    11.    
    12.    If Cmd Then
    13.       StrLen = lstrlenW(Cmd) * 2
    14.       If StrLen Then
    15.          ReDim Buffer(0 To (StrLen - 1)) As Byte
    16.          CopyMemory Buffer(0), ByVal Cmd, StrLen
    17.          CmdToSTr = Buffer
    18.       End If
    19.    End If
    20. End Function

    Then in the Open event Proc for the workbook add the following
    VB Code:
    1. Private Sub Workbook_Open()
    2. Dim CmdRaw As Long
    3. Dim CmdLine As String
    4.    
    5.     CmdRaw = GetCommandLine
    6.     CmdLine = CmdToSTr(CmdRaw)
    7.     MsgBox CmdLine
    8. End Sub


    Now, try passing an Excel command line with the /e switch followed by your list of variables, all seperated by forward slashes.
    Here's the command line I was using.

    "excel \\AUSCSRR206\DECLAN_X_KENNY$\DK_Test.xls /e/dk/var2"

    The e/ switch is vital here as you don't want Excel to open with a blank workbook.


    the Open code snippet above just shows you the string value. I haven't written the code to parse out the values at the end of the string, but that's the easy piece
    Last edited by DKenny; Nov 8th, 2005 at 04:46 PM.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

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



Click Here to Expand Forum to Full Width