Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 113
Default Copy Filenames AND details to Excel

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 419
Default Copy Filenames AND details to Excel

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" wrote in message
...
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
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
Type details into one cell and they copy into another slavenp Excel Discussion (Misc queries) 2 August 1st 07 09:38 AM
Macro for copy pasting details from main sheet hipul Excel Discussion (Misc queries) 1 June 26th 07 08:59 AM
Copy row details where cell value meets certain criteria Sarah (OGI) Excel Worksheet Functions 2 May 17th 07 05:06 PM
using excel to rename filenames? vmorgan Excel Discussion (Misc queries) 1 March 14th 06 06:12 PM
How do I copy subtotaled data without the underlying details? DBergesen Excel Worksheet Functions 1 December 15th 05 06:25 PM


All times are GMT +1. The time now is 11:45 PM.

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"