XLA Routines: EE_ImportFromFile

Nick's picture
EE_ImportFromFile is a routine that imports a sheet on a file and puts the results on the target range (the top left cell)
Sub EE_ImportFromFile(wbkFullPath As String, strSheet As String, rngTarget As range)
    Dim wbkSrc      As Workbook
    Dim wksSrc      As Worksheet
 
'http://excelexperts.com/xla-routines-eeImportFromFile    for updates on this function
    If EE_FileExists(wbkFullPath) = False Then Exit Sub
 
    Set wbkSrc = Workbooks.Open(wbkFullPath)
    Set wksSrc = wbkSrc.Worksheets(strSheet)
 
    wksSrc.UsedRange.Copy
    rngTarget.PasteSpecial xlPasteValues
    rngTarget.PasteSpecial xlPasteFormats
 
    Application.CutCopyMode = False
 
    wbkSrc.Close False
 
    Set wksSrc = Nothing
    Set wbkSrc = Nothing
End Sub