ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping through all workbooks (https://www.excelbanter.com/excel-programming/272926-looping-through-all-workbooks.html)

Abdul Salam[_3_]

Looping through all workbooks
 

Try somethin like this:

(un tested)


Public Sub GetData()

Dim MyDir As String
Dim MyFType As String
Dim MyWbook As String
Dim MyTWbook As String
Dim MyOpenWbook As Workbook
Dim MySheet As Worksheet
Dim MyCell As Range

MyTBook = "C:\My Directory\My Files\My Master
file.xls"
MyTBook.Open
MyDir = "C:\My Directory\My Files"
MyFType = "*.XLS"
MyWbook = Dir(MyDir & "\" & MyFType)
Do
Set MyOpenWbook = Workbooks.Open(MyDir & "\" &
MyWbook)
For Each MySheet In MyOpenWbook
If MySheet.Visible = True Then
MySheet.Range("A1").Copy
MyTBook.Activate
Range("A65536").End(xlUp).Offset(1,
0).Select
ActiveSheet.Paste
End If
Next MySheet

MyOpenWbook.Save
MyOpenWbook.Close
MyWbook = Dir()
Loop Until MyWbook = ""

End Sub


Abdul Salam


-----Original Message-----
Can someone give me a start to the code to open all the

workbooks in turn
that are in a specific directory and then to copy

specific cells to a
masterfile in a different directory? thanks in advance


.


Mervyn Thomas[_3_]

Looping through all workbooks
 
Many thanks - about test
Mervyn

"Abdul Salam" wrote in message
...

Try somethin like this:

(un tested)


Public Sub GetData()

Dim MyDir As String
Dim MyFType As String
Dim MyWbook As String
Dim MyTWbook As String
Dim MyOpenWbook As Workbook
Dim MySheet As Worksheet
Dim MyCell As Range

MyTBook = "C:\My Directory\My Files\My Master
file.xls"
MyTBook.Open
MyDir = "C:\My Directory\My Files"
MyFType = "*.XLS"
MyWbook = Dir(MyDir & "\" & MyFType)
Do
Set MyOpenWbook = Workbooks.Open(MyDir & "\" &
MyWbook)
For Each MySheet In MyOpenWbook
If MySheet.Visible = True Then
MySheet.Range("A1").Copy
MyTBook.Activate
Range("A65536").End(xlUp).Offset(1,
0).Select
ActiveSheet.Paste
End If
Next MySheet

MyOpenWbook.Save
MyOpenWbook.Close
MyWbook = Dir()
Loop Until MyWbook = ""

End Sub


Abdul Salam


-----Original Message-----
Can someone give me a start to the code to open all the

workbooks in turn
that are in a specific directory and then to copy

specific cells to a
masterfile in a different directory? thanks in advance


.





All times are GMT +1. The time now is 09:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com