Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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


.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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


.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping Maggie[_6_] Excel Discussion (Misc queries) 6 October 2nd 08 09:14 PM
Looping through 2 workbooks Pierre Excel Discussion (Misc queries) 3 March 7th 08 04:00 PM
Not Looping Roger Excel Discussion (Misc queries) 0 February 26th 08 05:18 PM
Looping David T Excel Discussion (Misc queries) 2 August 30th 06 10:51 PM
VBA code for looping through open workbooks and worksheets Jamie Martin[_2_] Excel Programming 1 July 24th 03 06:44 PM


All times are GMT +1. The time now is 12:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"