cweggleto81
New Member
- Joined
- Jan 11, 2018
- Messages
- 21
Hi Guys,Gals..
Option Explicit
Sub Macro1()
Dim objFSO As Object, objFolder As Object, objFile As Object
Dim strFolderName As String
Dim wb As Workbook
Dim lngMyRow As Long
Application.ScreenUpdating = False
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolderName = "C:\" '<-Foler containing Excel files. Remember trailing "\". Change to suit.
Set objFolder = objFSO.GetFolder(strFolderName)
For Each objFile In objFolder.Files
If InStr(objFSO.GetExtensionName(objFile.Name), "xls") > 0 Then 'Only interested in Excel files
Set wb = Workbooks.Open(objFolder & objFile.Name)
'Puts the data from the named ranges into the next available row in columns A, B abd C in 'Sheet1'. Change to suit if necessary.
On Error Resume Next 'In case there's no data in 'Sheet1' manually set the variable
lngMyRow = ThisWorkbook.Sheets("Sheet1").Range("A:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
If lngMyRow = 0 Then
lngMyRow = 2 'Default initial output row number. Change to suit if necessary
End If
On Error GoTo 0
With ThisWorkbook.Sheets("Sheet1")
.Range("A" & lngMyRow) = wb.Names("ACCNTNAME").RefersToRange
.Range("B" & lngMyRow) = wb.Names("ACCNTNUM").RefersToRange
.Range("C" & lngMyRow) = wb.Names("TOTALCOST").RefersToRange
End With
wb.Close False
End If
Next objFile
Application.ScreenUpdating = True
End Sub
Option Explicit
Sub Macro1()
Dim objFSO As Object, objFolder As Object, objFile As Object
Dim strFolderName As String
Dim wb As Workbook
Dim lngMyRow As Long
Application.ScreenUpdating = False
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolderName = "U:\New Charges\New Account Sheets\" '<-Foler containing Excel files. Remember trailing "\". Change to suit.
Set objFolder = objFSO.GetFolder(strFolderName)
For Each objFile In objFolder.Files
If InStr(objFSO.GetExtensionName(objFile.Name), "xlsx") > 0 Then 'Only interested in Excel files
Set wb = Workbooks.Open(objFolder & objFile.Name)
'Puts the data from the named ranges into the next available row in columns A, B abd C in 'Sheet1'. Change to suit if necessary.
On Error Resume Next 'In case there's no data in 'Sheet1' manually set the variable
lngMyRow = ThisWorkbook.Sheets("Sheet1").Range("A:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
If lngMyRow = 0 Then
lngMyRow = 4 'Default initial output row number. Change to suit if necessary
End If
On Error GoTo 0
With ThisWorkbook.Sheets("Sheet1")
.Range("A" & lngMyRow) = wb.Names("ACCNTNAME").RefersToRange
.Range("B" & lngMyRow) = wb.Names("ACCNTNUM").RefersToRange
.Range("C" & lngMyRow) = wb.Names("TOTALCOST").RefersToRange
End With
wb.Close False
End If
Next objFile
Application.ScreenUpdating = True
End Sub
Option Explicit
Sub Macro1()
Dim objFSO As Object, objFolder As Object, objFile As Object
Dim strFolderName As String
Dim wb As Workbook
Dim lngMyRow As Long
Application.ScreenUpdating = False
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolderName = "U:\New Charges\New Account Sheets\" '<-Foler containing Excel files. Remember trailing "\". Change to suit.
Set objFolder = objFSO.GetFolder(strFolderName)
For Each objFile In objFolder.Files
If InStr(objFSO.GetExtensionName(objFile.Name), "xlsx") > 0 Then 'Only interested in Excel files
Set wb = Workbooks.Open(objFolder & objFile.Name)
'Puts the data from the named ranges into the next available row in columns A, B abd C in 'Sheet1'. Change to suit if necessary.
On Error Resume Next 'In case there's no data in 'Sheet1' manually set the variable
lngMyRow = ThisWorkbook.Sheets("Sheet1").Range("A:C").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
If lngMyRow = 0 Then
lngMyRow = 4 'Default initial output row number. Change to suit if necessary
End If
On Error GoTo 0
With ThisWorkbook.Sheets("Sheet1")
.Range("A" & lngMyRow) = wb.Names("ACCNTNAME").RefersToRange
.Range("B" & lngMyRow) = wb.Names("ACCNTNUM").RefersToRange
.Range("C" & lngMyRow) = wb.Names("TOTALCOST").RefersToRange
End With
wb.Close False
End If
Next objFile
Application.ScreenUpdating = True
End Sub