-1
Good afternoon Peoples.
I’m working on a code that unzips a file ".xlsm", exchange the Vbproject and compact again. However a permission problem has arisen at the time of compacting, I hope you can help me.
Dim Fname As Variant, FileNameFolder As Variant, DefPath As String, strDate As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(ThisWorkbook.Path)
Set fc = f.Files
For Each f1 In fc
na = na & f1.Name
If Not na Like "*Update.xlsm" And Not na Like "*.bin" Then GoTo conl
na = ""
Next
Exit Sub
conl:
pat = ThisWorkbook.Path & "\"
fs.copyfile pat & na, pat & na & ".zip"
Fname = pat & na & ".zip"
DefPath = ThisWorkbook.Path
If Right(DefPath, 1) <> "\" Then DefPath = DefPath & "\"
FileNameFolder = DefPath & "pasta\"
MkDir FileNameFolder
Set oApp = CreateObject("Shell.Application")
oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(Fname).Items
fs.copyfile pat & "vbaProject.bin", pat & "pasta\xl\vbaProject.bin", True
Kill Fname
'alternativa(ocorre o mesmo problema)
'Open pat & na & ".zip" For Output As #1
'Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
'Close #1
'oApp.Namespace(Fname).CopyHere oApp.Namespace(FileNameFolder).Items
Set Folder = fs.GetFolder(FileNameFolder)
zipName = Folder.Name + ".zip"
fs.CreateTextFile(pat & zipName, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
Set zipFile = fs.GetFile(pat & zipName)
Set Source = oApp.Namespace(Folder.Path).Items
oApp.Namespace(zipFile.Path).CopyHere (Source)
On Error Resume Next
fs.deletefolder Environ("Temp") & "\Temporary Directory*", True
End Sub```
Grato desde já.
What is the error message?
– Evilmaax
@Evilmaax | I believe the message does not come from Excel, it is the following: "File not found or no read permission" and the title is "Compressed folder error (zipped)" ;)
– NRAlbukas