PDA

View Full Version : Solved: Count Files in Folder



omnibuster
01-20-2010, 05:13 PM
Hi.
This Msgbox says how many files is in this Folder, but if i want use this (i) for NewFile name ext get wrong results??
Need some help!


Sub GetiValue()
Dim SWs As SHDocVw.ShellWindows, vIE As SHDocVw.InternetExplorer, MyPath As String
Dim vFF As String, SubFolderName As String, FilesInPath As String, wkb As Workbook
Dim MyFiles() As String, FilePath, i As Long
Set SWs = New SHDocVw.ShellWindows

For Each vIE In SWs
If Left(vIE.LocationURL, 4) = "http" Then

MyPath = ThisWorkbook.Path
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"

FilesInPath = Dir(MyPath & "*.htm")

i = 0
Do While FilesInPath <> ""
i = i + 1
ReDim Preserve MyFiles(1 To i)
MyFiles(i) = FilesInPath
FilesInPath = Dir()
Loop

MsgBox i '.Value 'Get exsisting Files.value for New FileName
vFF = FreeFile
SubFolderName = ThisWorkbook.Path
FilePath = ActiveWorkbook.Path

If Right$(FilePath, 1) <> "\" Then FilePath = FilePath & "\"

Open FilePath & ("AB(i+1).htm") For Output As #vFF
Print #vFF, vIE.Document.Body.innerhtml
Close #vFF
End If
Next
Set SWs = Nothing
Set vIE = Nothing
End Sub

Bob Phillips
01-20-2010, 05:41 PM
Is it just



Open FilePath & ("AB(" & i + 1 & ").htm") For Output As #vFF

omnibuster
01-21-2010, 02:05 AM
Big Thanks xld.