Solved

Is it possible to change a cell to the creation date value of each xls file in a folder?

Posted on 2011-02-16
4
276 Views
Last Modified: 2012-05-11
I have a folder with many Excel workbook files, 2003 version, in each.
Each workbook file has the same format and the same two worksheet names.
One worksheet has a cell with a date in it.
Is it possible to write a macro in a new Excel file that will identify the creation date of each file within the folder and change the cell value within each of the files to the date that the file was created?
0
Comment
Question by:spar-kle
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Ken Fayal
ID: 34912759
You should be able to assign the value of the cell you want to

ActiveWorkbook.BuiltinDocumentProperties("Creation Date")

You can do this with VBA
0
 
LVL 50

Accepted Solution

by:
Dave Brett earned 500 total points
ID: 34913791
Hi again,

Something like this code would
- open every xls, xlsx, xlsm file under C;\temp
- write the create date in A1 of the first sheet as a date format
- close and save the file

Pls change this line
    strFolderName = "c:\temp"
to set your directory

This line
With Wb.Sheets(1).[a1]
if you wanted to change a different cell
ie for B10 on second sheet
With Wb.Sheets(2).[b10]

Cheers

Dave


Sub Change()
'uses http://www.experts-exchange.com/A_2839.html
    Dim Wb As Workbook
    Dim strFName As String
    Dim strFolderName As String
    strFolderName = "c:\temp"

    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
    End With

    strFName = Dir(strFolderName & "\*.xls*")
    Do While Len(strFName) > 0
        Set Wb = Workbooks.Open(strFolderName & "\" & strFName)
        With Wb.Sheets(1).[a1]
            .NumberFormat = "dd-mmm-yyyy"
            .Value = Wb.BuiltinDocumentProperties("Creation Date")
        End With
        Wb.Save
        Wb.Close
        strFName = Dir
    Loop

    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
        .StatusBar = vbNullString
    End With

End Sub

Open in new window

0
 

Author Comment

by:spar-kle
ID: 34919868
Sorry for delay, it's been a busy day...

Thanks CaptainKenbo, though not quite what I was after, I'll keep the code for future reference..

brettdj, ..that's excellent, and thankyou for the added explanations
Only problem is that the date is incorrect, I'm sure there must be a simple fix
ie todays date comes out as 07-Aug-2001
Can you please help..
Thanks
Des
0
 

Author Closing Comment

by:spar-kle
ID: 34920251
Thanks brettdj
Really good!!!!
My problem was with the formatting in the original files.
If I can't work it out I'll post another question
Thanks for your help, excellent
Des
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question