LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Loop thru files in DIR, delete worksheets & reset worksheet Name property??

Option Explicit
Sub VisibleTrue()
Dim basebook As Workbook
Dim mybook As Workbook
'Dim Item As Worksheet
Dim i As Long, j as Long
Dim sh as Object
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.LookIn = "C:\Data\DataFiles\Sept"
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
Set basebook = ThisWorkbook
For i = 1 To .FoundFiles.Count
Set mybook = Workbooks.Open(.FoundFiles(i))
Application.DisplayAlerts = False
sh.Worksheets(Array("Sheet1","Sheet3", _
"Sheet6", "Sheet10")).Delete
Application.DisplayAlerts = True
j = 0
For Each sh In Sheets
j = j + 1
sh.Name = j
sh.Visible = True
Next sh
j = 0
for each sh in Sheets
j = j + 1
sh.Name = "Sheet" & j
Next
myBook.Close SaveChanges:=True
Next i
End If
Application.ScreenUpdating = True
End Sub


--
Regards,
Tom Ogilvy

Mike Taylor wrote in message
om...
Can anyone share idea(s) for code that will programatically loop
through all the .xls files (each file has 10 worksheets) in a
directory and

1) delete the same four worksheets ("Sheet1", "Sheet10", "Sheet3", &
"Sheet6" from each of the .xls files, and then
3) change the worksheet Name property of the remaining six worksheets
so that the worksheet Name property of the first worksheet is
"Sheet1", the second worksheet is "Sheet2", etc.

Any ideas are greatly appreciated.



 
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
reset the range of FOR loop Farooq Sheri Excel Discussion (Misc queries) 1 April 7th 09 08:05 PM
Is it possible to reset the starting cell in a For Loop Ayo Excel Discussion (Misc queries) 2 May 12th 08 06:27 PM
Loop thru multiple files - Modify worksheet visible property Mike Taylor Excel Programming 1 October 24th 03 04:03 AM
Excel macro to loop through worksheets and graph data from each worksheet deb Excel Programming 5 October 17th 03 05:34 PM
Is there a Sheet delete property? David Excel Programming 5 August 21st 03 05:10 AM


All times are GMT +1. The time now is 01:07 PM.

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

About Us

"It's about Microsoft Excel"