LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default Macro doesn't loop through sheets of books in specific folder

Hi everyone,

I'm trying to select a folder then on each worksheet in each book I would
like to clear the contents of hidden rows 1-4 and then run David McRitchie's
Trimall routine on column H.

Sub PrepClear_Trimall()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False

On Error Resume Next

Set wbCodeBook = ThisWorkbook

With Application.FileSearch
.NewSearch
strFolder = InputBox("Please enter folder", "Path")
.LookIn = strFolder
.FileType = msoFileTypeExcelWorkbooks
.Filename = "*.xls"

If .Execute 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(.FoundFiles(lCount))

Dim Shts As Worksheet
'Carries out action for ALL worksheets in active workbook
For Each Shts In ActiveWorkbook.Worksheets
Shts.Rows("1:4").Select
Range("B1").Activate
Selection.ClearContents
Columns("H:H").Select
Range("H5").Activate
Call Trimall
Next
wbResults.Close SaveChanges:=True
Next lCount
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

I've pasted in some recorded macro bits and it works after a fashion but
only carries out the actions on the active sheet of each workbook it goes
into.

Where am I going wrong?

Thank you

--
Deirdre
 
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
A macro code to print multiple sheets in different w.books Gladiator Excel Discussion (Misc queries) 3 February 22nd 10 07:49 PM
Loop through files in a folder and unprotect sheets Diddy Excel Programming 13 August 15th 08 09:59 AM
work books only reference sheets in same folder... excel-chump[_2_] Excel Discussion (Misc queries) 0 October 15th 07 03:42 PM
Macro to sum sheets in a folder keri Excel Programming 11 January 18th 07 04:53 PM
Split all books in a folder MarkN Excel Programming 2 July 26th 06 03:44 AM


All times are GMT +1. The time now is 09:50 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"