vba - Passing arguments from command line in excel 2010 -


i have found several snippet of code out there allows me pass arguments excel command line.

the code below placed in new module called parameters:

declare function getcommandline lib "kernel32" alias "getcommandlinew" () long declare function lstrlenw lib "kernel32" (byval lpstring long) long declare sub copymemory lib "kernel32" alias "rtlmovememory" (mydest any, mysource any, byval mysize long)  public cmdlinetostr() string ' ' returns command line in call excel ' dim buffer() byte dim strlen long dim cmdptr long  cmdptr = getcommandlinew() if cmdptr > 0   strlen = lstrlenw(cmdptr) * 2   if strlen > 0     redim buffer(0 (strlen - 1)) byte     copymemory buffer(0), byval cmdptr, strlen     cmdlinetostr = buffer   end if end if  end sub 

and in thisworkbook call code

sub workbook_open()     msgbox parameters.cmdlinetostr end sub 

it fails getcommandline function, error due problems linking dll library or due fact have macros stored in personal.xlsb?

i call excel sheet command line line: c:\users\kim\desktop>start excel parameters.xlsm /e/nmbnmbmnb

and error :

eroor

outside procedure

change public cmdlinetostr() string

to public function cmdlinetostr() string

public cmdlinetostr() string not procedure, need put either sub or function procedure. hence error message "invalid outside procedure" because precisely outside procedure.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -