VBA창의 도구 > 참조 > "Microsoft Shell Controls And Automation"를 참조시켜준 다음,
Dim oApp As Object가 아니라 Dim oApp As Shell로 선언해줘야 압축을 풀어 준다.
'#2024-06-27. 압축 파일 해제 by abyul.com
Sub UnzipSomeFile()
Dim sTargetFileName As String
sTargetFileName = "workbook.xml"
'sTargetFileName = "all"
'From. https://officetricks.com/unzip-file-vba-excel-macro/
'Define Variable Data Types
Dim zipFileName As String
Dim unZipFolderName As String
Dim objZipItems As FolderItems
Dim objZipItem As FolderItem
'Set Zip File Name & Folder path to Unzip
zipFileName = "C:\Temp\zipTest.zip\xl"
'zipFileName = "C:\Temp\zipTest.xlsx\xl" 'zip이 아닌 xlsx로 하면 에러난다.
unZipFolderName = "C:\Temp\Extract"
'Early Binding Reference
'Add Tools -> Reference -> "Microsoft Shell Controls And Automation"
Dim wShApp As Shell
'Dim wShApp As Object 'Shell타입으로 선언하지 않고 Object로 선언하면 에러가 난다.
Set wShApp = CreateObject("Shell.Application")
Set objZipItems = wShApp.Namespace(zipFileName).Items
If sTargetFileName = "all" Then
'Extract: Unzip all Files to Folder
wShApp.Namespace(unZipFolderName).CopyHere objZipItems
Else
'Extract: Unzip only spcific File
For Each objZipItem In objZipItems
If objZipItem.Name = sTargetFileName Then
wShApp.Namespace(unZipFolderName).CopyHere objZipItem
End If
Next
End If
End Sub
VBA창의 도구 > 참조 > "Microsoft Shell Controls And Automation"를 참조시켜준 다음,