excel - Batch Convert TXT to XLS Using VBA -
i trying convert directory full of .txt files .xls using vba. using following code:
sub txtconvertxls() 'variables dim wb workbook dim strfile string dim strdir string 'directories strdir = "\\xx\xx\xx\xx\desktop\test\test1\" strfile = dir(strdir & "*.txt") 'loop while strfile <> "" set wb = workbooks.open(strdir & strfile) wb .saveas replace(wb.fullname, ".txt", ".xls"), 50 .close true end set wb = nothing loop end sub
the issue is: when run it, states there file name it's trying save in directory. name shows has .xls extension, if there assuredly no .xls's in directory yet! appreciated - thanks!
you seem missing strfile = dir
before loop
. without reprocessing same txt file.
while strfile <> "" set wb = workbooks.open(strdir & strfile) wb .saveas replace(wb.fullname, ".txt", ".xls"), 50 .close false '<-already saved in line directly above end set wb = nothing strfile = dir '<- stuffs next filename strfile loop
see dir function
Comments
Post a Comment