View Single Post
 
Old 03-27-2017, 03:28 PM
Logit Logit is offline Windows 10 Office 2007
Expert
 
Join Date: Jan 2017
Posts: 591
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

Probably need to see all of your code in that macro rather than just one line.

However ... two probable causes:

#1 - The file is no longer where you remember it being and Excel can't find it.

#2 - Part of your code is missing.

Regarding #2 ... example code:

Code:
Sub ImportWorksheet() 
    ' This macro will import a file into this workbook 
    Sheets("Sheet1").Select 
    PathName = Range("D3").Value  '<--- could easily be the actual path instead of the path written to a cell
    Filename = Range("D4").Value  '<-- could be the actual filename instead
    TabName = Range("D5").Value 
    ControlFile = ActiveWorkbook.Name 
    Workbooks.Open Filename:=PathName & Filename 
    ActiveSheet.Name = TabName 
    Sheets(TabName).Copy After:=Workbooks(ControlFile).Sheets(1) 
    Windows(Filename).Activate 
    ActiveWorkbook.Close SaveChanges:=False 
    Windows(ControlFile).Activate 
End Sub
Note there is a reference made to Filename and Pathname so Excel knows
what is meant by Filename:=PathName & Filename

Does you code provide the reference for fileloc ?
Reply With Quote