ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   modifiyng code (https://www.excelbanter.com/excel-programming/275459-modifiyng-code.html)

marwan hefnawy

modifiyng code
 
I have a folder that contains many subfolders, each of the subfolders
contains so many excel sheets with VBA code. The excel files are similar in
their structure and their code (but contain different data).
The problem is that I want to add (or delete or comment) some line of code
to all of the Excel sheets without opeining them one by one.
Is there a method for doing this?
Thanks




Chip Pearson

modifiyng code
 
Marwan,

You can loop through the folders, open each file, manipulate the VBA code as
needed, then close each file. Something like the following:


Dim Ndx As Long
Dim WB As Workbook
With Application.FileSearch
.NewSearch
.LookIn = "C:\ExcelProjects"
.SearchSubFolders = True
.Filename = "*.xls"
For Ndx = 1 To .Execute(msoSortByFileName)
Set WB = Workbooks.Open(.FoundFiles(Ndx))
'
' code to manipulate WB.VBProject
'
WB.Close savechanges:=True
Next Ndx
End With

In the code above, insert the specific code to delete or comment out the
code inside the For loop. You can find example code that modifies code
modules at www.cpearson.com/excel/vbe.htm .


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com



"marwan hefnawy" wrote in message
...
I have a folder that contains many subfolders, each of the subfolders
contains so many excel sheets with VBA code. The excel files are similar

in
their structure and their code (but contain different data).
The problem is that I want to add (or delete or comment) some line of code
to all of the Excel sheets without opeining them one by one.
Is there a method for doing this?
Thanks







All times are GMT +1. The time now is 12:31 PM.

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