很容易的,在www.rarlab.com下载UnRAR的OCX控件,可以直接使用,相当简单,而且在该压缩包中有VB解压的例子: If fso.FileExists(Text1.Text) = False Then MsgBox "File doesn't exist !" Exit Sub End If If Option1(0).Value = True Then UnRar1.Lister Text1.Text Else UnRar1.Decompress Text1.Text, Foldr End If
Public Function gCompress(ByVal pstrSource As String, ByVal pstrTarget As String, Optional IsCps As Boolean = True) As Boolean'文件压缩以及解压模块'pstrSource:压缩前的原始文件'pstrTarget:压缩后的目标文件'IsCps : 是解压:false 还是压缩: trueDim Rarexe As String 'WINRAR执行文件的位置
Dim FileString As String 'Shell指令中的字符串Dim Result As LonggCompress = TrueOn Error GoTo ErrIf IsCps = True Then '压缩
If fso.FileExists(Text1.Text) = False Then
MsgBox "File doesn't exist !"
Exit Sub
End If
If Option1(0).Value = True Then
UnRar1.Lister Text1.Text
Else
UnRar1.Decompress Text1.Text, Foldr
End If
Dim FileString As String 'Shell指令中的字符串Dim Result As LonggCompress = TrueOn Error GoTo ErrIf IsCps = True Then '压缩
Rarexe = App.Path & "\WinRAR.EXE"
FileString = Rarexe & " a -o+ -r -ep -m5 """ & pstrTarget & """ """ & pstrSource & """"
Result = Shell(FileString, vbHide)
Else '解压
Rarexe = App.Path & "\WinRAR.EXE"
FileString = Rarexe & " e -o+ """ & pstrSource & """ """ & pstrTarget & """"
Result = Shell(FileString, vbHide)
End IfExit FunctionErr:
MsgBox "文件压缩导出失败!请重新发送", vbOKOnly, "对不起"
Screen.MousePointer = 0
gCompress = FalseEnd Function