Using VB to open two specific .txt documents in excel, save the workbook as a certain name, and then reference the workbook -
i need program writing open specific .txt
documents in excel , save workbook name referenced in excel workbook. overall goal have workbook main cell a3 reference cell b5 workbook test1 created text documents. far can pull recent text document need third recent document in same workbook.
so example: folder c:\results
contains files:
test1_chr.txt test1_ftr.txt test1_hdr.txt test2_chr.txt test2_ftr.txt test2_hdr.txt
i need grab both test1 chr , hdr files , import them excel document. have far code (note: works far when txt file has been created same day think have tried 1 day , fine next without changing stopped working)
dim filename string dim mostrecentfile string dim mostrecentfilehdr string dim mostrecentdate date dim path string directory = "c:" filename = dir(directory & filespec, 0) if filename <> "" mostrecentfile = filename mostrecentdate = filedatetime(directory & filename) while filename <> "" if filedatetime(directory & filename) > mostrecentdate mostrecentfile = filename mostrecentdate = filedatetime(directory & filename) end if filename = dir loop end if path = "c:\results\" newestfile = path + mostrecentfile chdir "c:\results" workbooks.opentext filename:=newestfile, origin:= 437, startrow:=1; datatype:=xldelimited, textqualifier:=xlnone, consecutivedelimiter:=true, tab:=true, semicolon:=true, comma:=true, space:=true, other:=false, fieldinfo:=array(array(1, 1),etc... trailingminusnumbers:=true activewindow.smallscroll down:=-108
it looks if file not created same day run code skips through filename stuff , hops right array part.
once able recent hdr , chr documents open on same workbook regardless of when created need save original name test1.xls name of one. have tried using *_hdr.txt , things being new vb not sure if wildcards can used in type of application want used for.
i realize alot ask little information given appreciated
Comments
Post a Comment