How to Change a Modified Date in Excel VBE
- 1). Open the Excel software from the Windows program menu and open the Excel file you want to use to edit the file's date. Click the "Developer" tab or ribbon and click the VBA button to open your VBA code file.
- 2). Create the VBA variables. You need to set the variable for the "Modified Date" file attribute and the date you want to use for the modified date. The following code sets up your variables:
Dim file As String
Dim results As Boolean
Dim newdate As Double
Dim modified As FileDateToProcess - 3). Set up the file name. You use the "file" variable to set the file name. The following code sets up the file name string:
file = "myfile.xls"
Replace "myfile.xls" with any file name you want to modify. - 4). Change the modified date for the file. You use the Excel VBA "SetFileDateTime" function to edit the modified date. The following code changes the date to "1/1/2011":
newdate = "1/1/2011"
results = SetFileDateTime(FileName:=file, FileDateTime:=newdaate, WhichDateToChange:=modified, NoGMTConvert:=False) - 5). Display a success message to the user after the date is modified. The following code determines if any errors were found and displays the success message:
If results = True Then
Debug.Print "File successfully modified."
End If