Consulting

Results 1 to 3 of 3

Thread: Solved: Count Files in Folder

  1. #1

    Solved: Count Files in Folder

    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!

    [VBA]
    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
    [/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is it just

    [vba]

    Open FilePath & ("AB(" & i + 1 & ").htm") For Output As #vFF
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Big Thanks xld.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •