title: Passing arguments from command line in excel 2010
body: <p>I have found several snippet of code out there that allows me to pass arguments into excel from command line.</p>
  
  <p>The code below is placed in a new module called parameters:</p>
  
  <pre><code>Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineW" () As Long
  Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
  Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (MyDest As Any, MySource As Any, ByVal MySize As Long)
  
  Public CmdLineToStr() As String
  '
  ' Returns the command line in the call to Excel
  '
  Dim Buffer() As Byte
  Dim StrLen As Long
  Dim CmdPtr As Long
  
  CmdPtr = GetCommandLineW()
  If CmdPtr &gt; 0 Then
    StrLen = lstrlenW(CmdPtr) * 2
    If StrLen &gt; 0 Then
      ReDim Buffer(0 To (StrLen - 1)) As Byte
      CopyMemory Buffer(0), ByVal CmdPtr, StrLen
      CmdLineToStr = Buffer
    End If
  End If
  
  End Sub
  </code></pre>
  
  <p>and then in thisworkbook i call this code</p>
  
  <pre><code>Sub workBook_open()
      MsgBox Parameters.CmdLineToStr
  End Sub
  </code></pre>
  
  <p>It fails with the <code>GetCommandLine</code> function, so is the  error due to problems with linking the dll library or  is this due to the fact that i have some macros stored in personal.xlsb? </p>
  
  <p>I call the excel sheet from the command line with this line:
  <code>
  C:\Users\kim\Desktop&gt;start excel Parameters.xlsm /e/nmbnmbmnb</code></p>
  
  <p>and i get this error :</p>
  
  <p><img src="https://i.stack.imgur.com/Xq28R.png" alt="eroor"></p>
  
  <p><a href="http://www.mrexcel.com/forum/excel-questions/179919-invalid-outside-procedure.html" rel="noreferrer">Outside procedure</a></p>