Hey all, so I'm working with the following code to pull information from all workbooks in a folder.
Sub OpenFile()
Dim sPath As String
Dim sFil As String
Dim strName As String
Dim twbk As Workbook
Dim owbk As Workbook
Dim ws As Worksheet
Set twbk = ActiveWorkbook
sPath = "Q:\SAFETY\Leadership Safety Audit\Solomon\2018\Training Lab\Audits"
sFil = Dir(sPath & "*.xls")
Do While sFil <> ""
strName = sPath & sFil
Set owbk = Workbooks.Open(strName)
Set ws = owbk.Sheets(1)
ws.Range("A1:L1", Range("A" & Rows.Count).End(xlUp)).Copy
twbk.Sheets(1).Range("A65536").End(xlUp)(2).PasteSpecial xlPasteValues
owbk.Close False
sFil = Dir
Loop
twbk.Save
End Sub
It works, but I would like it to be more precise.
For starters, it will only pull from the active sheet of each in the folder.
Is there a way to be more specific? All of my workbooks have the information on the same sheet, all named 'Sheet 1', but aren't always the last sheet opened before save/close.
Thanks in advance.
Sub OpenFile()
Dim sPath As String
Dim sFil As String
Dim strName As String
Dim twbk As Workbook
Dim owbk As Workbook
Dim ws As Worksheet
Set twbk = ActiveWorkbook
sPath = "Q:\SAFETY\Leadership Safety Audit\Solomon\2018\Training Lab\Audits"
sFil = Dir(sPath & "*.xls")
Do While sFil <> ""
strName = sPath & sFil
Set owbk = Workbooks.Open(strName)
Set ws = owbk.Sheets(1)
ws.Range("A1:L1", Range("A" & Rows.Count).End(xlUp)).Copy
twbk.Sheets(1).Range("A65536").End(xlUp)(2).PasteSpecial xlPasteValues
owbk.Close False
sFil = Dir
Loop
twbk.Save
End Sub
It works, but I would like it to be more precise.
For starters, it will only pull from the active sheet of each in the folder.
Is there a way to be more specific? All of my workbooks have the information on the same sheet, all named 'Sheet 1', but aren't always the last sheet opened before save/close.
Thanks in advance.