Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Listing the files from a directory

I have about 5 - 6 textfiles which are available in a specific directory, I
have done a macro to identify these files & convert them to excel files. Now
I'm in a fix that some time there might be 3 files only or no file in that
folder.

In the Macro, I have refered the file (which is having constant name say
A,B,C...), if these files are available, the macro will open the text file &
convert them to excel. if say text file B is not available then macro stops
over here. how should I proceed further.

Alternatively, how should I get the list of text files available in a
particular folder & how this can be displayed in the excel worksheet in a
range.

thanks for the help.

regards,
yagna.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Listing the files from a directory

Try using the FileSystemObject?

"yagna" wrote in message
...
I have about 5 - 6 textfiles which are available in a specific directory,
I
have done a macro to identify these files & convert them to excel files.
Now
I'm in a fix that some time there might be 3 files only or no file in that
folder.

In the Macro, I have refered the file (which is having constant name say
A,B,C...), if these files are available, the macro will open the text file
&
convert them to excel. if say text file B is not available then macro
stops
over here. how should I proceed further.

Alternatively, how should I get the list of text files available in a
particular folder & how this can be displayed in the excel worksheet in a
range.

thanks for the help.

regards,
yagna.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Listing the files from a directory

Yagna,

Sub ProcessFiles()
Dim sPath As String, sName As String
Dim i As Long, sh As Worksheet
Dim bk As Workbook
Dim bListInsheet As Boolean

' Variable bListInSheet value
' True: List files in worksheet
' False: Open files and save as .xls

bListInsheet = False

Set sh = ActiveSheet

sPath = "C:\Myfolder\"
sName = Dir(sPath & "*.txt")
i = 1
Do While sName < ""
If bListInsheet Then
i = i + 1
sh.Cells(i, 1).Value = sName
Else
Set bk = Workbooks.Open(sPath & sName)
bk.SaveAs Replace(sPath & sName, _
".txt", ".xls"), _
xlWorkbookNormal
bk.Close Savechanges:=False
End If
sName = Dir
Loop
If bListInsheet Then _
sh.Cells(1, 1).Value = "File Name"
End Sub


--
regards,
Tom Ogilvy

"yagna" wrote:

I have about 5 - 6 textfiles which are available in a specific directory, I
have done a macro to identify these files & convert them to excel files. Now
I'm in a fix that some time there might be 3 files only or no file in that
folder.

In the Macro, I have refered the file (which is having constant name say
A,B,C...), if these files are available, the macro will open the text file &
convert them to excel. if say text file B is not available then macro stops
over here. how should I proceed further.

Alternatively, how should I get the list of text files available in a
particular folder & how this can be displayed in the excel worksheet in a
range.

thanks for the help.

regards,
yagna.

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
directory listing [email protected] Excel Programming 7 February 9th 07 06:43 PM
Listing all files in an online directory paulharvey[_12_] Excel Programming 1 June 2nd 06 06:55 AM
FTP Directory Listing GerbilGod7[_9_] Excel Programming 2 May 17th 06 04:53 PM
Directory listing Bampah Excel Discussion (Misc queries) 4 January 19th 06 03:25 PM
listing directory files in a spreedsheet automatically alex Excel Programming 2 November 22nd 05 04:01 PM


All times are GMT +1. The time now is 07:11 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"