Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Sub to check files in folder and remove Module1

I've got a bunch of .xls in say, D:\Maxh\Excel

Is there a sub I can use to run through that bunch of .xls
and remove Module1 from each .xls, if the Module1 exists?

Thanks



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Sub to check files in folder and remove Module1

Try some code like the following:

Sub AAA()
Dim FName As String
Dim WB As Workbook
Dim DirName As String

DirName = "C:\Test" '<< CHANGE DIRECTORY
ChDrive DirName
ChDir DirName

FName = Dir(DirName & "\*.xls")
Do Until FName = vbNullString
Set WB = Workbooks.Open(FName)
On Error Resume Next
With WB.VBProject.VBComponents
.Remove .Item("Module1")
End With
On Error GoTo 0
WB.Close savechanges:=True
FName = Dir()
Loop
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Thu, 30 Oct 2008 22:09:18 +0800, "Max"
wrote:

I've got a bunch of .xls in say, D:\Maxh\Excel

Is there a sub I can use to run through that bunch of .xls
and remove Module1 from each .xls, if the Module1 exists?

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Sub to check files in folder and remove Module1

Many thanks, Chip
It works well.


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
Check Folder For Files Dave Excel Discussion (Misc queries) 6 November 20th 07 11:16 PM
Check if a folder has x files in it. Dave Excel Discussion (Misc queries) 8 November 15th 07 03:35 PM
check to ensure all files in folder Sarah Excel Programming 2 June 15th 07 12:50 PM
Check if folder exists, if yes just copy sheet in to folder? Simon Lloyd[_787_] Excel Programming 3 June 19th 06 03:44 PM
Install ThisWorkbook and Module1 files with batch script Mark Excel Programming 3 August 30th 05 02:49 PM


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

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"