Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
LVS LVS is offline
external usenet poster
 
Posts: 2
Default List file names using VBA Dir instruction

I want to use VBA Excel 2007 to list the names of files in a particular
directory. I cannot use FileSearch, and need some guidance on use of
Dir("PathName",vbattribute). Which attribute responds to the name of the
file?.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default List file names using VBA Dir instruction

Hi Lvs,

I want to use VBA Excel 2007 to list the names of files in a particular
directory. I cannot use FileSearch, and need some guidance on use of
Dir("PathName",vbattribute). Which attribute responds to the name of the
file?.


The default one (you can omit the 2nd argument).

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com
Member of:
Professional Office Developer Association
www.proofficedev.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default List file names using VBA Dir instruction

See if the following example help. One retrieves Directories and the other
retrieves files.

Sub Test_Dir_Path()
'Returns directories for specified path

Dim MyPath As String
Dim myDirectory As String

MyPath = CurDir & "\" ' Set the path and add "\"

MsgBox "Current path is:- " & Chr(13) & _
MyPath 'For testing purposes

' Retrieve the first directory entry.
myDirectory = Dir(MyPath, vbDirectory)
Do While myDirectory < "" ' Start the loop.
' Ignore the current and encompassing directory.
If myDirectory < "." And myDirectory < ".." Then
' Test that is a directory
If (GetAttr(MyPath & myDirectory) And vbDirectory) _
= vbDirectory Then
MsgBox myDirectory 'For testing purposes
End If
End If
myDirectory = Dir 'Get next entry.
Loop
End Sub


Sub Test_Dir_Files()
'Returns files for specified path

Dim MyPath As String
Dim myFile As String

MyPath = CurDir & "\" ' Set the path and add "\"

MsgBox "Current path is:- " & Chr(13) & _
MyPath 'For testing purposes

' Retrieve the first entry.
myFile = Dir(MyPath)
Do While myFile < "" ' Start the loop.
MsgBox myFile
myFile = Dir 'Get next entry.

Loop
End Sub



--
Regards,

OssieMac


"LVS" wrote:

I want to use VBA Excel 2007 to list the names of files in a particular
directory. I cannot use FileSearch, and need some guidance on use of
Dir("PathName",vbattribute). Which attribute responds to the name of the
file?.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a list using the file names Garry Excel Discussion (Misc queries) 1 April 12th 10 03:53 PM
vba instruction for file saving umpire_43 Excel Programming 6 April 16th 08 11:12 PM
how can you list all of the worksheet names in a file harish Excel Discussion (Misc queries) 1 March 6th 06 04:13 PM
Getting a List of File Names gilgil Excel Programming 3 November 25th 05 09:39 AM
need to copy a long list of file names gilcola Excel Discussion (Misc queries) 6 August 19th 05 12:55 AM


All times are GMT +1. The time now is 01:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"