Jambi46n2
Active Member
- Joined
- May 24, 2016
- Messages
- 260
- Office Version
- 365
- Platform
- Windows
Code:
Dim wkbDest As Workbook Dim wkbSource As Workbook
Set wkbDest = ThisWorkbook
Dim LastRow As Long
Dim strPath As String
strPath = Range("G30").Value
ChDir strPath
Dim strExtension As String
strExtension = ("*.xlsx")
Do While strExtension <> ""
Set wkbSource = Workbooks.Open(strPath & strExtension)
With wkbSource
LastRow = .Sheets("SQL Pull").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Sheets("SQL Pull").Range("A2:AV" & LastRow).Copy wkbDest.Sheets("Combined SQL Pull").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
.Close savechanges:=False
End With
[COLOR=#ff0000] strExtension = Dir '<----- Run Time Error 5 here. "Invalid Procedure Call or Argument" [/COLOR]
Loop
The Code Above was intended to grab every file with the extension .xlsx from the folder path pasted in cell G30. Then find the worksheet named "SQL Pull", copy all the data minus the header, and paste into the workbook that is currently opened into the sheet "Combined SQL Pull". The code works for a little bit, then errors on the line in red above.
Can someone please assist on what needs to be done to make this work correctly?
Thank you in advance.