batch file - QueryTables Error: Expected ')' -


getting error: "expected ')'" on line 22, char 60 (i.e. right @ "connection" in querytables.add function). vba being called batch file. i'm trying understand wrong syntax can invoke vb job turn text file formatted csv. text file tab delimited.

batch file:

pushd %~dp0                    **used current dir set path=%~dp0                 **used set path variable send vbscript txttocsv.vbs %path%            **used invoke vbscript 

vba script:

if wscript.arguments.count < 1      wscript.echo "error! please specify source path , destination. usage: txttocsv destination.csv"      wscript.quit end if dim oexcel set oexcel = createobject("excel.application") oexcel.visible = false oexcel.displayalerts = false  dim obook set obook = oexcel.workbooks.add() obook     .title = "deal data"     .subject = "deal data"     .saveas wscript.arguments(0)&"deal_data.xlsx"&year(date)&month(date)&day(date) end  dim sourcefile set sourcefile = "text;"&wscript.arguments(0)&"deal_data.txt"  set activesheet = worksheets("sheet1") activeworkbook.activesheet.querytables.add(connection:="text;" & sourcefile,    destination:=activecell)     .name = "deal_data"         .fieldnames = true     .rownumbers = false     .filladjacentformulas = false     .preserveformatting = true     .refreshonfileopen = false     .refreshstyle = xlinsertdeletecells     .savepassword = false     .savedata = true     .adjustcolumnwidth = true     .refreshperiod = 0     .textfilepromptonrefresh = false     .textfileplatform = 437     .textfilestartrow = 1     .textfileparsetype = xldelimited     .textfiletextqualifier = xltextqualifierdoublequote     .textfileconsecutivedelimiter = false     .textfiletabdelimiter = true     .textfilesemicolondelimiter = false     .textfilecommadelimiter = false     .textfilespacedelimiter = false     .textfilecolumndatatypes = array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)     .textfiletrailingminusnumbers = true     .refresh backgroundquery:=false end  obook.close false oexcel.quit wscript.echo "done" 

your second script vbscript, not vba, though you're calling excel vba methods in it. while 2 languages share similarities, there fundamental differences.

  1. you need handle accessing vba methods , collections.

  2. you cannot use name arguments in vbscript.

also seem have constructed connection string in variable sourcefile.

change these 2 lines:

set activesheet = worksheets("sheet1") activeworkbook.activesheet.querytables.add(connection:="text;" & sourcefile,    destination:=activecell) 

into this:

set activesheet = obook.worksheets("sheet1") activesheet.querytables.add(sourcefile, oexcel.activecell) 

and problem should disappear.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -