Hello,
I need to open a text file and copy the data from it to a master Workbook.
Here is the code I managed to put together but I am having "Subscript out of range"
here is my code.
[VBA]Sub thetry()
Dim fileToOpen As Variant
'THIS WILL OPEN THE TEXT FILE I NEED
fileToOpen = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
Workbooks.OpenText Filename:=fileToOpen, _
DataType:=xlDelimited, Tab:=True
End If
'THIS SHOULD ACTIVATE THE NEW WORKBOOK THATS NAMED AFTER THE FILE THAT WAS OPENED
Windows(fileToOpen & ".txt").Activate '<============I am getting an error here
'THIS WILL COPY ALL THE CONTENTS FROM THE SHEET WITH THE SAME NAME AS THE WORKBOOK
ActiveWorkbook.Sheets(fileToOpen).Cells.Copy
'THIS WILL CLOSE THE WORKBOOK WITHOUT ANY NOTIFICATION AND THE COPIED DATA WILL STILL BE IN MY
'CLIPBOARD
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
'this will paste the data
Workbooks("Master").Activate
ActiveWorkbook.Sheets("Sheet1").Range("A1").Paste
End Sub
[/VBA]
Thanks for the help