You are on page 1of 4

Desbloquear excel macro

Dim FSO As Object


Dim oApp As Object
Dim Fname As Variant
Dim FileNameFolder As Variant
Dim DefPath As String
Dim strDate As String
Dim FileNameZip, FolderName, oFolder
Dim oApp1 As Object
Dim MyPath As String
Dim str As String

str = Application.GetOpenFilename("Excel Files


(*.xls;*.xlsb;*.xlsx;*.xlsm),*.xls;*.xlsb;*.xlsx;*.xlsm")
If Not str = "Falso" And Not str = "False" Then

lastSlash = InStrRev(str, "\")


'str1 = Mid(str, lastSlash + 1)

Caminho = str
Ponto = InStrRev(Caminho, ".")
Extensao = Mid(Caminho, Ponto + 1, Len(Caminho) -
Ponto)
Caminho_Zip = Left(Caminho, Ponto - 1) & ".zip"
Nome_Arquivo = Mid(Caminho, InStrRev(Caminho, "\")
+ 1, Len(Caminho))
Pasta_Arquivo = Replace(Caminho, "\" &
Nome_Arquivo, "")
Nome_Arquivo_1 = Mid(Caminho, InStrRev(Caminho,
"\") + 1, Ponto - InStrRev(Caminho, "\") - 1)

Call Limpa_Pasta

Name Caminho As Caminho_Zip

Fname = Caminho_Zip
DefPath = Pasta_Arquivo
If Right(DefPath, 1) "\" Then
DefPath = DefPath & "\"
End If

FileNameFolder = DefPath & "Arquivo1\"

MkDir FileNameFolder

Set oApp = CreateObject("Shell.Application")

oApp.Namespace(FileNameFolder).CopyHere
oApp.Namespace(Fname).items
On Error Resume Next
Set FSO =
CreateObject("scripting.filesystemobject")
FSO.deletefolder Environ("Temp") & "\Temporary
Directory*", True

Arquivos = Dir(FileNameFolder & "xl\worksheets\


*.xml")
Valor_Substituido = ""

While Arquivos Empty

Close #1
Open FileNameFolder & "xl\worksheets\" &
Arquivos For Input As #1
strFinal = Empty
Texto_Final = Empty
While EOF(1) = False

Line Input #1, strLine


Valor_Ini_xls = InStr(strLine,
"<sheetProtection password")
Valor_Ini_xlsx = InStr(strLine, " 0 Then
Valor_Fim = InStr(Valor_Ini_xls,
strLine, ">")
Texto_Final = Left(strLine,
Valor_Ini_xls - 1) & Valor_Substituido & Mid(strLine,
Valor_Fim + 1, Len(strLine))
End If
If Valor_Ini_xlsx > 0 Then
Valor_Fim = InStr(Valor_Ini_xlsx,
strLine, ">")
Texto_Final = Left(strLine,
Valor_Ini_xlsx - 1) & Valor_Substituido & Mid(strLine,
Valor_Fim + 1, Len(strLine))
End If
strFinal = strFinal + Texto_Final
Wend
Texto_Final = Empty
Close #1

Open FileNameFolder & "xl\worksheets\" &


Arquivos For Output As #1
Print #1, strFinal
Close #1

Arquivos = Dir()
Wend

DefPath = Pasta_Arquivo
If Right(DefPath, 1) "\" Then
DefPath = DefPath & "\"
End If

FileNameZip = DefPath & Nome_Arquivo_1 & ".zip"

Set oApp1 = CreateObject("Shell.Application")

NewZip (FileNameZip)

FolderName = DefPath & "Arquivo1"


If Right(FolderName, 1) "\" Then
FolderName = FolderName & "\"
End If

oApp1.Namespace(FileNameZip).CopyHere
oApp1.Namespace(FolderName).items

On Error Resume Next


Do Until oApp1.Namespace(FileNameZip).items.Count =
oApp1.Namespace(FolderName).items.Count
Application.Wait (Now + TimeValue("0:00:01"))
Loop
On Error GoTo 0

Name Caminho_Zip As Caminho


Call Limpa_Pasta
Call Limpa_Pasta
MsgBox "Arquivo Desprotegido com Sucesso!",
vbInformation, "Atenção!"
End If
End Sub

Sub NewZip(sPath)
If Len(Dir(sPath)) > 0 Then Kill sPath
Open sPath For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) &
String(18, 0)
Close #1
End Sub
Sub Limpa_Pasta()
On Error Resume Next
Set FSO = CreateObject("scripting.filesystemobject")

MyPath = Pasta_Arquivo & "\Arquivo1"

If Right(MyPath, 1) = "\" Then


MyPath = Left(MyPath, Len(MyPath) - 1)
End If

If FSO.FolderExists(MyPath) = True Then


Application.Wait (Now + TimeValue("0:00:02"))
FSO.deletefolder MyPath & "\*.*", True
FSO.deletefolder MyPath
End If
On Error GoTo -1
End Sub

You might also like