I am creating a macro that will open a list of files - as held as strings in the main workbook - and then copy a named sheet from each into the active workbook. The problem I have is that the code keeps failing with file not found even though the string content is correct.
Code:
Sub Consolidate_MI()'Start timer to record time elapsed
Dim StartTime As Double
Dim SecondsElapsed As Double
Dim fromwb As Workbook 'workbook from which to copy
Dim towb As Workbook 'this workbook
Dim strfullfile As String 'file full path from which to copy
Dim strfromsh As String 'from sheet to copy
Dim strtosh As String 'to sheet to copy into
Dim lngfromrow As Long 'start row from where data will be found in the copy from worksheet
Dim strfromcell As String 'cell to copy from
StartTime = Timer
Set towb = ThisWorkbook
'Maximise running speed
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.CalculateBeforeSave = False
' Open each file listed, clear the original copy of the tab and recopy.
Sheets("Summary").Select 'Position on Summary tab in this spreadsheet
Range("C12").Select 'Select the first file path
Do Until ActiveCell.Value = "" 'Start DO - stop when a blank entry found i.e. no more files to consolidate
strfullfile = ActiveCell.Value 'Populate variables to be used in the copy
strfromsh = ActiveCell.Offset(0, 1).Value 'now populate the from sheet
strtosh = ActiveCell.Offset(0, 2).Value 'now the copy To sheet
lngfromrow = ActiveCell.Offset(0, 3).Value 'The start position of the data - row - A assumed
Set fromwb = Workbooks.Open(strfullfile, False, True) 'open the workbook from which to copy