excel - Relative paths for VBScript file -


i have vbscript file open excel file , run macro. excel file located in same folder vbscript file. use relative paths call it, can move folder around without rewriting paths in script. right vbscript looks this:

    option explicit      on error resume next      excelmacroexample      sub excelmacroexample()         dim xlapp        dim xlbook        set xlapp = createobject("excel.application")        set xlbook = xlapp.workbooks.open("c:\users\ben\desktop\geocodingbatchfile\files\geocodingstart.xlsm")        xlapp.run "export"       xlapp.quit         set xlbook = nothing        set xlapp = nothing       end sub  

rather using full file path, great if this:

    set xlbook = xlapp.workbooks.open(".\geocodingstart.xlsm")  

you can use filesystemobject path script file, this

sub excelmacroexample()     dim xlapp    dim xlbook    dim fso    set fso = createobject("scripting.filesystemobject")    dim fullpath    fullpath = fso.getabsolutepathname(".")    set fso = nothing    set xlapp = createobject("excel.application")    set xlbook = xlapp.workbooks.open(fullpath & "\geocodingstart.xlsm")    xlapp.run "export"    xlapp.quit     set xlbook = nothing    set xlapp = nothing  end sub 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -