PC Review


Reply
Thread Tools Rate Thread

Copy Filenames AND details to Excel

 
 
deeds
Guest
Posts: n/a
 
      7th Dec 2007
Below is some code that I use to get display the filenames from directories
into excel. However, it only brings in the filename...how can I also get the
details portion of it...namely the modified date? Any ideas.
Thanks in advance


Sub AllFilenames()
Rem Change D:\ to your folder path
D = "C:\MY FILES\"
Cells(1, 1) = "Filenames"
r = 2
f = Dir(D, 7)
Do While f <> ""
Cells(r, 1) = f
r = r + 1
f = Dir
Loop
End Sub
 
Reply With Quote
 
 
 
 
Conan Kelly
Guest
Posts: n/a
 
      7th Dec 2007
deeds,

I haven't tested this, but I think it will do what you are asking.

It will prompt you to select any file in the folder you want to list the
contents of.

I used the object variable "pfsoFile" for file system files. If you put
your cursor any where below the variable declarations and type "pfsoFile."
(<--notice there is a dot/period at the end), the VBE should list all the
properties of file system files that you can return.

(Make sure to set a reference to MS Scripting Runtime library)





Option Explicit

Sub ChangeFileNames()
Dim pfso As New FileSystemObject
Dim pfsoFolder As Folder
Dim pfsoFile As File
Dim pstrFileDate As String
Dim pdteFileDate As Date
Dim pstrFile As String
Dim pstrFolder As String
Dim pintCounter As Integer

pintCounter = 2

pstrFile = Application.GetOpenFilename(, , "Please select any file in
the folder that you want to list the contents for")

pstrFolder = Left(pstrFile, InStrRev(pstrFile, "\"))

'MsgBox pstrFolder

'Set pfsoFolder = pfso.GetFolder("C:\MY FILES\")
Set pfsoFolder = pfso.GetFolder(pstrFolder)

Cells(1, 1) = "File Names"
Cells(1, 2) = "Modified Date"


For Each pfsoFile In pfsoFolder.Files
Cells(pintCounter, 1) = pfsoFile.Name
Cells(pintCounter, 2) = pfsoFile.DateLastModified
pintCounter = pintCounter + 1
Next pfsoFile
End Sub



HTH,

Conan





"deeds" <(E-Mail Removed)> wrote in message
news:078BB229-F4F4-4996-952B-(E-Mail Removed)...
> Below is some code that I use to get display the filenames from
> directories
> into excel. However, it only brings in the filename...how can I also get
> the
> details portion of it...namely the modified date? Any ideas.
> Thanks in advance
>
>
> Sub AllFilenames()
> Rem Change D:\ to your folder path
> D = "C:\MY FILES\"
> Cells(1, 1) = "Filenames"
> r = 2
> f = Dir(D, 7)
> Do While f <> ""
> Cells(r, 1) = f
> r = r + 1
> f = Dir
> Loop
> End Sub



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I copy subtotaled data without underlying details in Excel Diletto Microsoft Excel Worksheet Functions 1 11th Jun 2009 11:06 PM
Copy Filenames into Excel steve Microsoft Excel Discussion 6 28th May 2007 09:26 PM
Copy Shipping details on form to billing details subform Ultraviolet47 Microsoft Access 6 10th Jan 2007 08:56 PM
Filenames and details blank in Windows Explorer until selected David Bower Windows XP Help 2 29th Oct 2004 04:18 PM
Copy/Paste filenames but NOT files Tyler Windows XP Help 5 5th Nov 2003 05:24 AM


Features
 

Advertising
 

Newsgroups
 


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