View Single Post
 
Old 12-25-2020, 12:16 PM
Purfleet Purfleet is offline Windows 10 Office 2019
Expert
 
Join Date: Jun 2020
Location: Essex
Posts: 345
Purfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to behold
Default

A bit basic, but this should do what you want.

The file location needs to be in cell B1 and the file name in B2

Code:
Sub ImportFile()

    Dim fLocation As String
    Dim fName As String
    Dim CurrentfName As String
    
    CurrentfName = ActiveWorkbook.Name
    fLocation = ActiveSheet.Range("B1")
    fName = ActiveSheet.Range("b2")
    
    If Len(Dir(fLocation & fName, vbDirectory)) = 0 Then
        MsgBox Title:="Error", Prompt:="Cant find file"
        Exit Sub
    End If
    
    If Right(fLocation, 1) <> "/" Then
        fLocation = fLocation & "/"
    End If
    
    Workbooks.Open (fLocation & fName)
    
    ActiveSheet.Copy Workbooks(CurrentfName).Sheets(1)
    
    Workbooks(fName).Close False

End Sub
Attached Files
File Type: xlsm Example_Purfleet.xlsm (20.2 KB, 8 views)
Reply With Quote