Date using VBA , Excel Pivot

imfarhan

Board Regular
Joined
Jan 29, 2010
Messages
125
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I have application which creates the excel reports using Ms Excel Template , the template called "abc.xls" and the output file which generates every day will be called "abc_01062011.xls" automatically.

The abc file has two sheets Data and Pivot
In pivot sheet I have the formula =Today() whic pulls today system date.
but the problem is that when the user open the report some other days' it shows system/Today's date instead of the day when the file was created.

I have used the following VBA code on the Pivot_Sheet

Code:
Private Sub Workbook_Open()
Code:
Range("D1").Value = Format(ThisWorkbook.BuiltinDocumentProperties("Creation Date"), "short date")
'Range("D1").Value = Format(ThisWorkbook.BuiltinDocumentProperties("Last Save Time"), "short date")
End Sub

The first line i above VBA code for "Creation date" and the 2nd line is for when the file updated. When the application generates the output reports it shows the Date when the "Template" was created instead of the new file(abc_01062011) which created today.

I have also used the "Last Save Time" but it doesn't like that as well and pulls "bring the last update date of the Template again instead of actual generated report which is abc_01062011.xls

Is there any other way withouth VBA , coz Today() functions works OK on "Data" sheet where no Pivot exist.

I hope it does make sense to all
I appreciate your help

Regards

Farhan
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi, Farhan

It doesn't quite make sense to me. Though I'm still sure whatever you want can be done. With VBA or even without.

With VBA might be better. Perhaps when the file is created to change the =TODAY() cell's entry to a value. Such as if the cell has a defined name - so that the code will always reference the same cell regardless of row/column insertions/deletions - like

range("YourCellDefinedName").value = clng(date)
or something like that.

Without VBA, you could have a formula - either in a worksheet or defined name - that takes the text from the end of the file name and converts that to a date.

HTH. regards
 
Upvote 0
Thaks for the response.

I have change my VBA code using "Define" function I think its working but I will check tomorrow how the applicatin will handle it when The Excel template runs live.

I have moved my VBA code to "ThisWorkBook" instead of sheet1(Pivot) becaue define "define_dt" can be call from any where.
so my VBA code is as follow:-

Code:
Private Sub Workbook_Open()
   Range("d_define").Value = CLng(Date)
End Sub

So will give you an update tomorrow.

Thanks for you help!
Farhan
 
Upvote 0
Thanks again Fazza
I check the reports its working fine today
Regards
F
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top