' goes down the rows in the table, the looks up the file name and range entered and uses the wcSun field 
' to align data with dates

' Usage: type everything within the inverted commas into the command line to perform a given action, do not include the inverted commas: 

'    "dataimport"  in the command line will run the program using tbl_import
'    "data import 2"   in the command line will run the program but only import the variable(s) that you have enetered in tbnl_import on row 2
'    "data import 23" as above but with row 23
logmode  +addin 
'logmode +e
'logmode +all


tbl_import(1,1) ="File"
tbl_import(1,2) ="Sheet Name"
tbl_import(1,3) ="Range"
tbl_import(1,4) ="ID"
tbl_import(1,5)="Import (Y/N)"
tbl_import(1,6)="Last loaded"


				
if @isobject("tbl_import") =0 then
	!i=@uiPrompt("Need to create a tbl_import with list of workfiles to import from")
	stop
endif	
if %0="" then
	for !i=2 to 100
		if @upper(tbl_import(!i,5))="Y" then
			if tbl_import(!i,1)<>"" then
				tbl_import(!i,7)=""
				%Dir=tbl_import(!i,1)
				%id=tbl_import(!i,4)
				%shtRng=tbl_import(!i,2)+"!"+tbl_import(!i,3)
				!oEC=@errorCount

				import(type=excelxml, c=max) %dir range=%shtRng @id {%id}
%err=@lasterrstr
					if @errorcount>!oEC then 			
						statusline %err
					else
						tbl_import(!i,6)=@STRNOW("dd/mm/yy") + " " + @time
					endif			
			else
				stop
			endif
		endif
	next
else
		!i=@val(%0)
		%Dir=tbl_import(!i,1)
		%id=tbl_import(!i,4)
		%shtRng=tbl_import(!i,2)+"!"+tbl_import(!i,3)
		!oEC=@errorCount
		import(type=excelxml, c=max) %dir range=%shtRng @id {%id}
			if @errorcount>!oEC then 
				stop
			else
				tbl_import(!i,6)=@STRNOW("dd/mm/yy") + " " + @time
			endif
endif


