View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Himansu Himansu is offline
external usenet poster
 
Posts: 40
Default Multiple Files to Import

Dom,

Ths makes sense, but I would have to change the
code manually fo reach job. I might have 3 files todat
and 5 files on some other day. The name would be:

hha_text1.txt
hha_text2.txt
hha_text3.txt
....etc.

Can I make hha_text%.txt a varabile and perform
the calculations for each worksheet?

--
Thanks,
Himansu



wrote in message
ups.com...
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)."