View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default RP - Add contents of cell A1 in all workbooks within a folder

Would that be because you declare

Function FileCountOK(pzFolder as Object)

to require the folder (as string) passed as an argument?

If FilecountOK("C:\Myfolder") then

--
Regards,
Tom Ogilvy


"Steph" wrote in message
...
Thanks for the follow-up Bob. I ran it, but I get an "Argument not
optional" error on the line
If FileCountOK Then
Am I doing something wrong? I'm runnung the ProcessFiles sub. Thanks!

"Bob Phillips" wrote in message
...
Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

Sub ProcessFiles()
Dim FSO As ObjectDim fldr As Object
Dim sFolder As String
Dim Folder As Object


Set FSO = CreateObject("Scripting.FileSystemObject")

sFolder = "C:\evaluation"

If sFolder < "" Then
Set Folder = FSO.GetFolder(sFolder)
If FileCountOK Then
StephsMacro
End If
End If ' sFolder < ""

End Sub

Function FileCountOK(pzFolder as Object)
Dim i As Long
Dim file As Object
Dim Files As Object

FileCountOK = TRUE
Set Files = pzFolder.Files
For Each file In Files
If file.Type = "Microsoft Excel Worksheet" Then
i=i+1
Workbooks.Open Filename:=file.Path
With ActiveWorkbook
FileCountOK = .Activesheet.Range("AQ1").Value = 1
.Close savechanges:=False
If Not FileCountOK The Exit Function
End With
End If
Next file

End Function


--

HTH

RP