Error when using VBA to import comma separated text file to worksheet - Excel 2013 -


i using vb code created recording macro. need import text, content of csv file worksheet. code used below.

when first ran code, got error

run-time error 5, invalid procedure call or argument

i searched internet , found few people saying code generated includes line .commandtype = 0, allegedly microsoft bug there no command 0 , should omit line. commented out , worked - while.

now, few hours later, coming same error. have excluded commandtype =0 line , included it, same error. have single-stepped code know stopping.

can this, or provide better code please? developing in excel 2013/365, used on mix of excel 2007, 2010 , 2013 pcs.

by way, have included of code includes prompt user asking if want import data, , puts time stamp on worksheet date/time source data file created. have included in case there issue within code.

sub read_por800() ' ' read_por800 macro ' read csv file 'por800.csv' named folder worksheet 'data' '  'part 1: prompt ask user if want update worksheet 'data'  dim lresult date       'text display shown here.     mynote = "do want update worksheet 'data'?"      'display messagebox - note text in capitals. label message box.     answer = msgbox(mynote, vbquestion + vbyesno, "question")      ' there 'if' statement see if user hit 'no' button     if answer = vbno          'code no button press - quit routine         exit sub      end if  ' answer yes, continue      activesheet.querytables.add(connection:= _         "text;c:\temp\por800.csv", destination:=range("$a$1")) '        .commandtype = 0         .name = "por800_1"         .fieldnames = true         .rownumbers = false         .filladjacentformulas = false         .preserveformatting = true         .refreshonfileopen = false         .refreshstyle = xlinsertdeletecells         .savepassword = false         .savedata = true         .adjustcolumnwidth = true         .refreshperiod = 0         .textfilepromptonrefresh = false         .textfileplatform = 850         .textfilestartrow = 1         .textfileparsetype = xldelimited         .textfiletextqualifier = xltextqualifierdoublequote         .textfileconsecutivedelimiter = false         .textfiletabdelimiter = true         .textfilesemicolondelimiter = false         .textfilecommadelimiter = true         .textfilespacedelimiter = false         .textfilecolumndatatypes = array(1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _         1, 1)         .textfiletrailingminusnumbers = true         .refresh backgroundquery:=false     end  ' update date , time 'por800' filename , store in g2 on worksheet t2 show time , date data generated.  lresult = filedatetime("c:\temp\por800.csv") worksheets("t2").range("g1").value = lresult  end sub  group customer  item    description customer stock 03/06/15 supplier stock    03/06/15  reject stock 03/06/15   ipro stock 03/06/15 weekly usage    safety    stock target  total @ sea    arrive week beginning 31/05/15  arrive week beginning 07/06/15  arrive week beginning 14/06/15  arrive week beginning 21/06/15  arrive week beginning 28/06/15  arrive week beginning 05/07/15  remaining orders cover supplier    customer demand f/c jun f/c jul f/c aug f/c sep f/c oct s05 000-f00316  m3x16 mscr csk pas  0   0   0   144 0           0   0   0   0   0   0   0   0   0   0   0   0   0 s05 000-f00408  mscr m4x8 csk pas   0   0   0   0   0           0   0   0   0   0   0   0   0   0   0   0   0   0 s05 000-p00308-w    m3x8 mscr pan w/fs pas  0   0   0   0   0           0   0   0   0   0   0   0   0   0   0   0   0   0 s05 000-p00310-w    m3x10 mscr w/s pas  0   0   0   0   0           0   0   0   0   0   0   0   0   0   0   0   0   0 s05 000-p00312-pn   m3x12 mscr pan nylon nat    0   0   0   48  0           0   0   0   0   0   0   0   0   0   0   0   0   0 

sorry - noticed cut , pasted csv file whilst opened in excel. below extract whilst open in notepad++. comma separated.

csv extract version

group customer,item,description,customer stock 03/06/15,supplier stock 03/06/15,reject stock 03/06/15,ipro stock 03/06/15,weekly usage,safety stock target,total @ sea,arrive week beginning 31/05/15,arrive week beginning 07/06/15,arrive week beginning 14/06/15,arrive week beginning 21/06/15,arrive week beginning 28/06/15,arrive week beginning 05/07/15,remaining orders cover  supplier,customer demand,f/c jun,f/c jul,f/c aug,f/c sep,f/c oct s05,000-f00316,m3x16 mscr csk pas,0,0,0,144,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0 s05,000-f00408,mscr m4x8 csk pas,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0 s05,000-p00308-w,m3x8 mscr pan w/fs     pas,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0 s05,000-p00310-w,m3x10 mscr w/s pas,0,0,0,0,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0 s05,000-p00312-pn,m3x12 mscr pan nylon nat,0,0,0,48,0,,,0,0,0,0,0,0,0,0,0,0,0,0,0 


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -