VBA用shell命令来压缩文件

 

Sub zipFile()
    Dim winrarPath$, fullname$, filename$, filePath
    winrarPath = "c:\program files\winrar\winrar.exe a -afzip "
    filePath = Application.GetOpenFilename
    If filePath <> False Then
        fullname = StrReverse(Split(StrReverse(filePath), "\")(0))
        filename = Split(fullname, ".")(0)
        Shell winrarPath & filename & " " & fullname
    End If
End Sub

 

 

注:此代码只能压缩单个文件。压缩多个文件的需要传入一个压缩后的文件名,代码也差不多,不难,大家想想也就出来了。
posted @ 2010-06-06 23:00  RobinLao  阅读(808)  评论(0编辑  收藏  举报