Hello,
I have taken this codes from web, I had tried to import excel file on active sheet but it does not copy the data from the fetched workbook.
I want to copy the details of called workbook sheet1 A-D data on the active sheet and close the called workbook.Any other way of doing this with ease.
Sub OpenSingleFile()
Dim Filter As String, Title As String
Dim FilterIndex As Integer
Dim Filename As Variant
' File filters
Filter = "Excel Files (*.xls),*.xls," & _
"Text Files (*.txt),*.txt," & _
"All Files (*.*),*.*"
' Default Filter to *.*
FilterIndex = 3
Title = "Select a File to Open"
ChDrive ("C")
ChDir ("C:\data")
With Application
Filename = .GetOpenFilename(Filter, FilterIndex, Title)
ChDrive (Left(.DefaultFilePath, 1))
ChDir (.DefaultFilePath)
End With
If Filename = False Then
MsgBox "No file was selected."
Exit Sub
End If
ImportThisOne CStr(Filename)
End Sub
Sub ImportThisOne(sFileName As String)
On Error Resume Next
Dim oBook As Workbook
Workbooks.Open sFileName
Set oBook = ActiveWorkbook
'Now do your processing on the newly imported sheet
On Error Resume Next
'Copy new sheet into this workbook
oBook.Worksheets(Sheet1).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
'close text file, do not save changes
oBook.Close False
Set oBook = Nothing
End Sub
Bookmarks