Adding Timestamp When a Macro Runs on Excel 2010

Background: The attached two files are Excel 2010 (Loader.xlms) that needs to be updated and the other one is a text file (SampleData) storing the data set.  Sheet1 and Sheet2 work together on this file.  User clicks on the button (Refresh Data) on Sheet2 which runs the ImportProcess macro to update the data residing on Sheet1 by opening the text file and pulling the data into Sheet1. This macro makes two macro calls one is to delete the range before the update and the other to open the text file and pull data in. DataImport macro uses external data connection and import feature.  Data set on Sheet1 needs to be updated twice a day everyday.  

Question1:   I need to add a timestamp on Sheet2 under the header TIME STAMP in column A.  Each time the user runs the macro by clicking on the "refresh data" button on Sheet2 to update the data set on Sheet1 of the Loader.xlsm file time should be captured, Excel needs to create a timestamp for this action and also needs to keep a history for each update by displaying the timestamp.  The format of the timestamp should be displaying date, hour, min, second.

Question2:  Upon resolving the first question I will also need to create an auto update process so the user does not have to manually click on the button twice a day but rather macro should run on predetermined times by itself.

Thanks in advance for help
Ray ErdenBusiness Systems AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
The answer to your first question is simple. Change the code in Module1 to read thusly:

Option Explicit

Sub ImportProcess()

    Call Timestamp
    Call DeleteDataRange
    Call ExternalDataImport

End Sub

Sub Timestamp()
    Dim LastR As Long
    With ThisWorkbook.Worksheets("Sheet2")
        .Range("1:1").NumberFormat = "yyyy-mm-dd hh:mm:ss"
        LastR = .Cells(.Rows.Count, 1).End(xlUp).Row
        .Cells(LastR + 1, 1) = Now
        .Cells(1, 1).Resize(LastR + 1, 1).Sort Key1:=.Cells(1, 1), Order1:=xlDescending, Header:=xlYes
    End With
End Sub

Open in new window

I suggest you go with a new question for the second item.  Running that macro automatically at preset times is done best via the Windows task scheduler.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I agree with the above comment regarding update I also prefer using vbs ,run it as cscript on specific times using windows task  scheduler.
but if you insist in using excel macros then the I think the best way to do it  is to make it check on workbook open  event when you validate time,
regarding time it is better to check for text file last modify date so refresh data is only valid if there is new version of the file
Ray ErdenBusiness Systems AnalystAuthor Commented:
Thank you it works the way I wanted.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.