|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
之前超版发的帖子,2个帖子,是将excel转换并压缩。我电脑里是RAR格式,对照着修改了,但是出现文件夹多层问题。求帮忙怎么检查修改呢
测试产出的压缩见附件。
- 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
- If InStr(ActiveWorkbook.Name, "EH(大熊)") > 0 Then
- With ActiveWorkbook
- TheRarexe = "C:\Program Files\WinRAR\WinRAR" '系统WINRAR路径
- '.SaveCopyAs "C:\Users\Administrator\Documents\Excelhome\EH(大熊)-" & Format(Date, "yyyy.mm.dd") & "-" & .Name '另存为C盘根目录下,作为压缩用的临时文件
- .SaveCopyAs "C:\Users\Administrator\Documents\Excelhome\EH(大熊)-" & Format(Date, "yyyy.mm.dd") & Mid(.Name, 18, InStrRev(.Name, ".xl") - 1) '另存为C盘根目录下,作为压缩用的临时文件
- TheSource = "C:\Users\Administrator\Documents\Excelhome\EH(大熊)-" & Format(Date, "yyyy.mm.dd") & Mid(.Name, 18, InStrRev(.Name, ".xl") - 1) '临时文件作为压缩源文件
- TheTarget = "C:\EH(大熊)-" & Format(Date, "yyyy.mm.dd") & Mid(.Name, 18, InStrRev(.Name, ".xl") - 18) & ".rar" '保存到目录
- TheFileString = TheRarexe & " 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") & Mid(.Name, 18, 99) '另存为C盘根目录下,作为压缩用的临时文件
- End With
- Else
- With ActiveWorkbook
- TheRarexe = "C:\Program Files\WinRAR\WinRAR" '系统WINRAR路径
- .SaveCopyAs "C:\Users\Administrator\Documents\Excelhome\EH(大熊)-" & Format(Date, "yyyy.mm.dd") & "-" & .Name '另存为C盘根目录下,作为压缩用的临时文件
- TheSource = "C:\Users\Administrator\Documents\Excelhome\EH(大熊)-" & Format(Date, "yyyy.mm.dd") & "-" & .Name '临时文件作为压缩源文件
- TheTarget = "C:\Users\Administrator\Documents\Excelhome\EH(大熊)-" & Format(Date, "yyyy.mm.dd") & "-" & Mid(.Name, 1, InStrRev(.Name, ".xl") - 1) & ".rar" '保存到目录
- TheFileString = TheRarexe & " a " & TheTarget & " " & TheSource
- TheResult = Shell(TheFileString, vbHide) '压缩
- Application.Wait Now + TimeValue("00:00:02")
- Kill TheSource '删除临时文件
- '.SaveAs "C:\Users\Administrator\Documents\Excelhome\EH(大熊)-" & Format(Date, "yyyy.mm.dd") & "-" & .Name '另存为C盘根目录下,作为压缩用的临时文件
- End With
- End If
- Application.DisplayAlerts = True
- End Sub
复制代码
http://club.excelhome.net/thread-866132-1-1.html
http://club.excelhome.net/thread-865133-1-1.html
|
|