Multiple Files to Import
If you already know the number and names of the text files, then I
would do the following in VBA:
Public Sub AddSheet
dim b as Excel.Workbook
set b = ActiveWorkbook
call ImportText (b, "<File_1")
call ImportText (b, "<File_2")
call ImportText (b, "<File_3")
....
End Sub
Private Sub ImportText (b as Excel.Workbook, FileName as string)
dim x as Excel.Workbook
dim s as Excel.Worksheet
set x = Excel.Application.Workbooks.open(FileName, ...)
call ActiveSheet.cells.copy
set s = b.Worksheets.Add
s.Name = FileName
call s.cells(1,1).activate
call s.Paste
x.Close
end sub
Hope this helps,
Dom
Himansu wrote:
Hello everyone,
I have multiple .txt files that I import into excel and
perform various calculations. I'm trying to automate
this process, but here's the problem:
** There might be one .txt file or multiple .txt files
that I import (depending on the project). Each
worksheet represents an imported .txt file. If there
are 7 worksheets then 7 files were inported. What
is the best method of automating this? Should the .txt
files be a variable? How can I accomplish this?
** Any help will be greatly appreciated.
--
Thanks,
Himansu
"Power tends to corrupt, and absolute power corrupts absolutely (Lord Acton,
1887)."
|