[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

收藏: QQ书签 del.icio.us 订阅: Google 抓虾

最新评论

发表评论

* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 
 

分类小组论坛
杂谈, 娱乐、八卦, 文学、艺术, 体育, 旅游、同城, 象牙塔, 情感, 时尚、生活, 星座, 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定