信手拈来 妙手偶得 » 日志 » [VBA]获取文件变更时间的系列函数
[VBA]获取文件变更时间的系列函数
Junglesong 发表于 2006-04-18 13:32:20

程序的意图是取出存放在批注中的路径,和文件名组成全路径名,再取出变化时间。
最后两个函数有点参考价值。
程序如下:
Option Explicit
'//******************************************************************************
'// 名称 :FetchModifyTime
'// 説明 :Fetch File Modify Time
'// 引数 :無
'// 戻り :無
'// 著者 :junglesong@gmail.com
'//******************************************************************************
Sub FetchModifyTime()
Dim sheetName As String
Dim i As Integer
Dim iMax As Integer
iMax = Sheets.Count
For i = 1 To iMax
sheetName = Sheets(i).Name
If sheetName = "最新モジュール一覧" Then
Call processSheet(i)
End If
Next i
End Sub
'//******************************************************************************
'// 名称 :ProcessSheet
'// 説明 :Process proper Sheet
'// 引数 :Sheet's Index
'// 戻り :無
'// 著者 :junglesong@gmail.com
'//******************************************************************************
Private Function processSheet(index As Integer)
Dim row, col, rowMax, colMax As Integer
rowMax = 100
colMax = 10
Dim currCell As Range
Dim filePath As String
For row = 1 To rowMax
For col = 1 To colMax
Set currCell = Sheets(index).Cells(row, col)
If hasComment(currCell) Then
filePath = Trim(currCell.comment.Text + "\" + Sheets(index).Cells(row, col - 1).Text)
currCell.Value = getFileModifyTime(filePath)
End If
Next col
Next row
End Function
'//******************************************************************************
'// 名称 :hasComment
'// 説明 :Judge if one cell has comment
'// 引数 :cell
'// 戻り :True,False
'// 著者 :junglesong@gmail.com
'//******************************************************************************
Private Function hasComment(cell As Range)
On Error GoTo errHandle
Dim comment As String
comment = cell.comment.Text
hasComment = True
Exit Function
errHandle:
hasComment = False
End Function
'//******************************************************************************
'// 名称 :getFileModifyTime
'// 説明 :get one file's modify time
'// 引数 :cell
'// 戻り :modify time
'// 著者 :junglesong@gmail.com
'//******************************************************************************
Private Function getFileModifyTime(filePath As String) As String
On Error GoTo errHandle
Dim fso As New Scripting.FileSystemObject
Dim currFile As file
Set currFile = fso.GetFile(filePath)
getFileModifyTime = currFile.DateLastModified
Exit Function
errHandle:
getFileModifyTime = Err.Description
On Error GoTo 0
End Function
完整下载地址:
http://www.blogjava.net/Files/junglesong/fetchModifyTime.rar
