ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Perform action on every workbook in a directory (https://www.excelbanter.com/excel-programming/352532-perform-action-every-workbook-directory.html)

Btibert[_8_]

Perform action on every workbook in a directory
 

Hello everyone,

All of my workbooks in a directory have the same format. As it stands
now, I open each one manually, and have my code extract the data from a
sheet and aggregate it on the appropriate sheet of my report file.

All I am looking to do is open each workbook, perform my macro, close
the work book and open the next. I figure to do this correctly, the
macro would have to count the workbooks in the directory (there are
51), and from 1-n, open work book, call my macro, close workbook, next
n.

tony h[_55_]

Perform action on every workbook in a directory
 

Sub a()
Dim wkb As Workbook
Dim strPath As String
Dim strFile As String

strPath = "C:\myfiles\" your path
strFile = Dir(strPath & "*.xls")
Do While strFile < ""
Set wkb = Workbooks.Open(strPath & strFile)
'do your bits
wkb.Close savechanges:=True
strFile = Dir()
Loop
MsgBox "done"
End Sub

regards


--
tony h
------------------------------------------------------------------------
tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
View this thread: http://www.excelforum.com/showthread...hreadid=509000


Btibert[_9_]

Perform action on every workbook in a directory
 

Thats perfect, thank you very much.


--
Btibert
------------------------------------------------------------------------
Btibert's Profile: http://www.excelforum.com/member.php...fo&userid=8559
View this thread: http://www.excelforum.com/showthread...hreadid=509000



All times are GMT +1. The time now is 11:59 PM.

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