Import text file in VBA

Regular Contributor

Hello Everyone,

I have written the code, after run the code it works well.

 

But it always start from A1

Screenshot (5860).png

I want to show start from D1.

 

So, what should i add in VBA code?

 

Please help..

 

Here is a attached file.

1 Reply

@Zan_Hanifee 

Public Sub ImportTextFile()
    Dim CurFile As Workbook
    Dim NewSheet As Worksheet
    Dim TextFile As Workbook
    Dim OpenFiles() As Variant
    Dim i As Integer
    Set CurFile = ActiveWorkbook
    OpenFiles = GetFiles()
    Application.ScreenUpdating = False
    For i = 1 To UBound(OpenFiles)
        Set NewSheet = CurFile.Worksheets.Add
        Set TextFile = Workbooks.Open(OpenFiles(i))
        TextFile.Sheets(1).Range("A1").CurrentRegion.Copy Destination:=NewSheet.Range("D1")
        NewSheet.Name = TextFile.Name
        Application.CutCopyMode = False
        TextFile.Close
    Next i
    Application.ScreenUpdating = True
End Sub

Public Function GetFiles() As Variant
    GetFiles = Application.GetOpenFilename(Title:="Select File(s) to Import", MultiSelect:=True)
End Function