|
楼主 |
发表于 2012-5-9 15:07
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 shaowu459 于 2012-5-9 17:13 编辑
- Sub Winrar()
- Application.DisplayAlerts = False
- Dim TheRarexe As String 'WINRAR程序的位置
- Dim TheSource As String '压缩前的源文件
- Dim TheTarget As String '压缩好的文件
- Dim TheFileString As String
- Dim TheResult As Long
- With ActiveWorkbook
- TheRarexe = "C:\Program Files\WinZip\WINZIP32" '系统WINRAR路径
- .SaveCopyAs "C:\Users\clarkshao\Desktop\EH(超人)-" & Format(Date, "yyyy.mm.dd") & "-" & .Name '另存为D盘根目录下,作为压缩用的临时文件
- TheSource = "C:\Users\clarkshao\Desktop\EH(超人)-" & Format(Date, "yyyy.mm.dd") & "-" & .Name '临时文件作为压缩源文件
- TheTarget = "C:\Users\clarkshao\Desktop\EH(超人)-" & Format(Date, "yyyy.mm.dd") & "-" & Mid(.Name, 1, InStrRev(.Name, ".xl") - 1) & ".zip" '保存到目录
- TheFileString = TheRarexe & " -min -a " & TheTarget & " " & TheSource
- TheResult = Shell(TheFileString, vbHide) '压缩
- Application.Wait Now + TimeValue("00:00:02")
- Kill TheSource '删除临时文件
- .SaveAs "C:\Users\clarkshao\Desktop\EH(超人)帖子附件\EH(超人)-" & Format(Date, "yyyy.mm.dd") & "-" & .Name '另存为D盘根目录下,作为压缩用的临时文件
- End With
- Application.DisplayAlerts = True
- End Sub
-
复制代码 终于搞定了!! |
|