Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Counting filenames in directory (2003)

    I am try to get a message box to return a count of all .doc files within a that is selected and stored as an array. I would like it to count all of the .doc within all the directories select.

    The array is called strSource(11)

    I have managed to do this once within access vba but can't get it right in word vba

    Many thanks.
    Regards
    Gerbil (AKA Kevin)

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Counting filenames in directory (2003)

    What was the code you used in Access? It's not likely to be specific to Access so it shouldn't be hard to adapt it for use in Word.

  3. #3
    3 Star Lounger
    Join Date
    Jul 2008
    Location
    Suffolk, United Kingdom
    Posts
    308
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Counting filenames in directory (2003)

    When I done it in Access I created a form and when I selected the directories same way I do in this word vba script it count each directory then added it the a text box, the I used another text box to add them all together. (I was trying to create a graphical front end to the word script, as others are using the script with me)

    In access VBA I dont no how to get it to look at each 'strSource(1)' 'strSource(2)''strSource(3)''strSource(4)' etc Max 11 and count the files inside each.

    Thanks Hans
    Regards
    Gerbil (AKA Kevin)

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Counting filenames in directory (2003)

    You can store the count in a variable instead of in a text box.
    You can loop through the items of the array:

    Dim i As Integer
    Dim lngCount As Long
    Dim lngCountSource As Long
    For i = 1 To 11
    If Not strSource(i) = "" Then
    ' Code to count files in strSource(i) folder goes here
    lngCountSource = ...
    ' Add to overall count
    lngCount = lngCount + lngCountSource
    End If
    Next i
    MsgBox "I counted " & lngCount & " files."

Posting Permissions

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