我在Excel中有一个vba宏,它从sharepoint站点下载.rar文件并将其解压缩。下载工作正常,我可以看到文件夹中下载的文件,但提取文件不起作用。 我将仅粘贴提取文件的部分,以便我的代码看起来像这样
Sub Extract()
Dim RarIt As String
Dim Source As String
Dim Desti As String
Dim WinRarPath As String
WinRarPath = "C:\Program Files\WinRar\"
Source = "C:\Reports\EMEA Load.rar"
Desti = "C:\Reports\"
RarIt = Shell(WinRarPath & "WinRar.exe e " & Source & " " & Desti, vbNormalFocus)
End Sub
所以当我运行它时,它会返回一个消息框"找不到档案"虽然我可以在文件夹中看到.rar文件。
我创建了另一个解决方案,一个解压缩文件的功能
Function Unzip(str_FILENAME As String)
Dim oApp As Object
Dim Fname As Variant
Dim FnameTrunc As Variant
Dim FnameLength As Long
Dim FnamePath As Long
Fname = str_FILENAME
FnamePath = InStrRev(Fname, "\")
FnameTrunc = Left(Fname, FnamePath)
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(FnameTrunc).CopyHere oApp.Namespace(Fname).Items
End Function
我在我的Sub中调用此函数,它适用于.zip文件,但对于.rar文件,它会返回此错误
"命名空间对象ishelldispatch6的方法失败"
Sub Extract2()
Dim strFilePath As String
strFilePath = "C:\Reports\EMEA Load.rar"
Unzip (strFilePath)
End Sub
请问我需要在代码中更改哪些内容?非常感谢你。
答案 0 :(得分:1)
因为文件名中有空格,我们需要用[...]
state_category = town
history={
victory_points = { 00001 8 }
history={
owner = FRA
buildings = {
infrastructure = 4
industrial_complex = 1
air_base = 1
3838 = {
naval_base = 3
}
}
add_core_of = FRA
}
provinces={
3838 9851 11804
}
}
括起来:
Chr(34)