Hi Jonny,
Does the original code that you posted work?
If so if you replace
FolderPath = "C:\Users\Peter\invoices\"
with
FolderPath = Sheets("Sheet1").Range("B5").Value
and then put this into B5
Formula:
C:\Users\Peter\invoices\
it should work.
Also check that the sheet name is Sheet1.
Otherwise try this (a full version of my second option combined with your code):
Sub MergeAllWorkbooks()
Dim Path As String, StrFile As String, FileName As String
Dim ShellApp As Object
Dim NRow As Long
Dim WorkBk As Workbook
Dim SummarySheet As Worksheet
Dim SourceRange As Range, DestRange As Range
Set SummarySheet = Workbooks.Add(xlWBATWorksheet).Worksheets(1)
NRow = 1
Set ShellApp = CreateObject("Shell.Application").BrowseForFolder(0, "Please choose a folder", 0, OpenAt)
Path = ShellApp.self.Path & "\"
StrFile = Dir(Path & "*")
Do While Len(StrFile) > 0
Set WorkBk = Workbooks.Open(Path & StrFile)
SummarySheet.Range("A" & NRow).Value = FileName
'Set the source range to be A9 through C9. Modify this range for your workbooks. It can span multiple rows.
Set SourceRange = WorkBk.Worksheets(1).Range("A9:C9")
'Set the destination range to start at column B and be the same size as the source range.
Set DestRange = SummarySheet.Range("B" & NRow)
Set DestRange = DestRange.Resize(SourceRange.Rows.Count, SourceRange.Columns.Count)
DestRange.Value = SourceRange.Value
NRow = NRow + DestRange.Rows.Count
WorkBk.Close savechanges:=False
StrFile = Dir
Loop
SummarySheet.Columns.AutoFit
End Sub
Otherwise you may have to attach files with test data.
Bookmarks