给你一个例子,从网上找的参考我稍微改了一下,我是在A1中填入了一个形如2012-2-14 14:05:08的日期,然后调用apiSetFileTime(文件名,最后修改时间,创建时间,访问时间)
如果只需要改最后访问时间,其它两个时间用""空值就可以了。
Option Explicit
Private Const OF_READWRITE = &H2
Private Const OFS_MAXPATHNAME = 128
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type
Private Declare Function SystemTimeToFileTime Lib "kernel32" ( _
lpSystemTime As SYSTEMTIME, _
lpFileTime As FILETIME) As Long
Private Declare Function LocalFileTimeToFileTime Lib "kernel32" ( _
lpLocalFileTime As FILETIME, _
lpFileTime As FILETIME) As Long
Private Declare Function SetFileTime Lib "kernel32" ( _
ByVal hFile As Long, _
lpCreationTime As FILETIME, _
lpLastAccessTime As FILETIME, _
lpLastWriteTime As FILETIME) As Long
Private Declare Function OpenFile Lib "kernel32" ( _
ByVal lpFileName As String, _
lpReOpenBuff As OFSTRUCT, _
ByVal wStyle As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Sub test()
Dim t As String
t = Format(Range("a1").Value, "yyyy/mm/dd HH:mm:ss")
If apiSetFileTime("e:\md5.exe", t, t, t) Then MsgBox "修改成功" Else MsgBox "修改失败"
End Sub
Function apiSetFileTime(ByVal PathName As String, ByVal LastWriteTime As String, Optional ByVal CreationTime As String, Optional ByVal LastAccessTime As String) As Boolean
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(PathName)
Dim myLastWriteTime, myCreationTime, myLastAccessTime
myLastWriteTime = IIf(LastWriteTime = "", f.DateLastModified, LastWriteTime)
myCreationTime = IIf(CreationTime = "", f.DateCreated, CreationTime)
myLastAccessTime = IIf(LastAccessTime = "", f.DateLastAccessed, LastAccessTime)
Dim rtn As Long
Dim hFile As Long
Dim ofs As OFSTRUCT
Dim lpCreationTime As FILETIME
Dim lpLastWriteTime As FILETIME
Dim lpLastAccessTime As FILETIME
If CreationTime = "" Then CreationTime = LastWriteTime
If LastAccessTime = "" Then LastAccessTime = LastWriteTime
lpCreationTime = TransformTime(myCreationTime)
lpLastWriteTime = TransformTime(myLastWriteTime)
lpLastAccessTime = TransformTime(myLastAccessTime)
hFile = OpenFile(PathName, ofs, OF_READWRITE)
rtn = SetFileTime(hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime)
If rtn = 1 Then apiSetFileTime = True
CloseHandle hFile
End Function
Private Function TransformTime(ByVal NewDate As String) As FILETIME
Dim fTime As FILETIME
Dim fLTime As FILETIME
Dim fSysTime As SYSTEMTIME
With fSysTime '参数 NewDate 的格式 : "yyyy/mm/dd HH:mm:ss"
.wYear = Year(NewDate)
.wMonth = Month(NewDate)
.wDay = Day(NewDate)
.wHour = Hour(NewDate)
.wMinute = Minute(NewDate)
.wSecond = Second(NewDate)
.wMilliseconds = 0
End With
SystemTimeToFileTime fSysTime, fLTime
LocalFileTimeToFileTime fLTime, fTime
TransformTime = fTime
End Function
Excel 2010 开发人员参考 > Excel 对象模型参考 > Workbook 对象 > 属性
Excel 开发人员参考
Workbook.BuiltinDocumentProperties 属性
返回一个 DocumentProperties 集合,该集合表示指定工作簿的所有内置文档属性。只读。
语法
表达式.BuiltinDocumentProperties
表达式 一个代表 Workbook 对象的变量。
说明
本属性返回的是内置文档属性的整个集合。通过指定属性的名称或集合索引号(数字),用 Item 方法可返回集合中的单个成员(一个 DocumentProperty 对象)。
可通过索引值或名称来引用文档属性。下面的列表显示的是可用的内置文档属性的名称:
标题
主题
作者
关键字
批注
模板
上一个作者
修订次数
应用程序名
上次打印日期
创建日期
上次保存时间
编辑时间总计
页数
字数
字符数
安全性
类别
格式
经理
单位
字节数
行数
段落数
幻灯片数
备注数
隐藏幻灯片数
多媒体剪辑数
超链接基础
字符数(包含空格)