Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fill sheet with directory conents

Status
Not open for further replies.

ninash

Technical User
Jul 6, 2001
163
GB
Hi All,

Please could someone let me know how to place a list of file names directly into an excel 97 spreadsheet.

Only 1 column needs to be filled

Any help with this problem would be greatfully accepted.

Tony
 
Sub DoDir()
' Display the names in C:\ that represent directories.
myPath = "c:\" ' Set the path.
MyName = Dir(myPath, vbDirectory) ' Retrieve the first entry.
DirCount = 0
Do While MyName <> &quot;&quot; ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> &quot;.&quot; And MyName <> &quot;..&quot; Then
' Use bitwise comparison to make sure MyName is a directory.

If InStr(1, MyName, &quot;.sys&quot;) = 0 Then
theAttrib = GetAttr(myPath & MyName)
If (theAttrib And vbDirectory) = vbDirectory Then
ActiveCell.Offset(DirCount).Value = myPath & MyName
DirCount = DirCount + 1
End If ' it represents a directory.
End If
End If
MyName = Dir ' Get next entry.
Loop



End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top