My problem is that I want to copy all the filenames from a required folder to a word document. Please note I want to copy all the filenames from the folder one by one. So please suggest me how to use the folder command such as ListIndex, ListCount and Filename.
I am able to access the folder by getting path name etc. assigning a variable and inputbox.
20-05-2002 at 06:01 AM
|
JLRodgers Level: Moderator Registered: 04-04-2002 Posts: 1616
Re: file names Archived to Disk
Assuming you have a list control added, the following will put all the file names into the list box (just as an example to show how it's done).
Option Explicit
Private Sub Form_Load()
Dim i As Integer
For i = 0 To File1.ListCount - 1
File1.ListIndex = i 'which item in list
List1.AddItem File1.FileName 'Name selected
Next
End Sub
[Edited by JLRodgers on 21-05-2002 at 11:17 AM GMT]
20-05-2002 at 07:52 PM
|
csmuley Level: Guest
Re: Re: file names Archived to Disk
Thanks for your reply.
Please get my problem again, I want to copy the names of the files (from a particular given folder) and paste them in word document one by one. If possible in a table. I do not want to creat a ListBox.
Please suggest a solution.
Thanks Once again.
CS Muley
25-05-2002 at 07:56 AM
|
JLRodgers Level: Moderator Registered: 04-04-2002 Posts: 1616
Re: file names Archived to Disk
For any inserting or whatever, just replace the List1.AddItem with the code to where you want it put.
For a database table:
Private Sub DataBase()
Dim i As Integer
Dim adc As New ADODB.Connection
Dim ars As New ADODB.Recordset
Set adc = New ADODB.Connection
Set ars = New ADODB.Recordset
For i = 0 To File1.ListCount - 1
File1.ListIndex = i 'which item in list
ars.AddNew
ars.Fields("FileName") = File1.FileName 'Name selected
ars.Update
Next
If ars.State = adStateOpen Then ars.Close
If adc.State = adStateOpen Then adc.Close
Set ars = Nothing
Set adc = Nothing
End Sub
to insert into word or a file, it'd be similar to the first code; just once again, replacing the List1.Additem with the filename, or insert command for word.
25-05-2002 at 06:04 PM
|
csmuley Level: Guest
Re: Re: file names Archived to Disk
Thanks for your kind suggestion. My problem is solved now.
Once again thanks for your quick reply.
CS Muley
quote:JLRodgers wrote:
For any inserting or whatever, just replace the List1.AddItem with the code to where you want it put.
For a database table:
Private Sub DataBase()
Dim i As Integer
Dim adc As New ADODB.Connection
Dim ars As New ADODB.Recordset
Set adc = New ADODB.Connection
Set ars = New ADODB.Recordset
For i = 0 To File1.ListCount - 1
File1.ListIndex = i 'which item in list
ars.AddNew
ars.Fields("FileName") = File1.FileName 'Name selected
ars.Update
Next
If ars.State = adStateOpen Then ars.Close
If adc.State = adStateOpen Then adc.Close
Set ars = Nothing
Set adc = Nothing
End Sub
to insert into word or a file, it'd be similar to the first code; just once again, replacing the List1.Additem with the filename, or insert command for word.