Importing Text File

  • Thread starter Thread starter gunny1979
  • Start date Start date
G

gunny1979

Hi Guys,

has anyone got a macro where I can import a text file saved on my
computer into a new sheet named yesterdays or todays date in format
"ddmmyy" and then the sheet gets hidden.

Thanks in advance for your help

Gunny
 
Sub ImportData()
ThisWorkbook.Sheets.Add after:=Sheets(Sheets.Count)
ActiveSheet.Name = Format(Date, "ddmmyy")
Workbooks.Open FileName:="C:\text.txt", Format:=2
Cells.Copy ThisWorkbook.Sheets(Format(Date, "ddmmyy")).[a1]
Workbooks("text.txt").Close savechganges:=False
Sheets(Format(Date, "ddmmyy")).Visible = False
End Sub

Change "C:\text.txt" to refer to your file. I've assumed that the file
is comma-delimited. If it's not, change the "Format:=2" to whatever you
need it to be (check Help for the Open method for the options).

Col
 
Hi Gunny,

use macro recorder. In case you will need to modify the recorded code,
post it in the forum.

Regards,
Ivan
 
Back
Top