How to not references from Shell and automation ?

VBAEXCELNew

New Member
Joined
Apr 3, 2023
Messages
38
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi,
i wanted to do an Unzip file without using the references from Shell and Automation however currently i am facing issue of doing late blind then a early blind as early blind work in unzip my files
Here is my vba code


VBA Code:
Sub UnzipAll()
    'Define Variable Data Types
    Dim sourceFolder As String
    Dim destinationFolder As String
    Dim objZipItems As FolderItems
    Dim objZipItem As FolderItem

    ' Get the current user's username
    userName = Environ("USERNAME")

    'Set the source and destination folders
    sourceFolder = "C:\Users\" & userName & "\Desktop\Price checker for FA\"
    destinationFolder = "C:\Users\" & userName & "\Desktop\Price checker for FA\"

    'Early Binding Reference
    'Add Tools -> Reference -> "Microsoft Shell Controls & Automation"
    Dim wShApp As Shell
    Set wShApp = CreateObject("Shell.Application")
    
    ' Check if there are any zip files in the source folder
    If Dir(sourceFolder & "*.zip") = "" Then
        MsgBox "No zip files found in the source folder."
        Exit Sub
    End If
    
    'Loop through all ZIP files in the source folder
    Dim file As Variant
    file = Dir(sourceFolder & "*.zip")

    Do While file <> ""
        'Set Zip File Name
        Dim zipFileName As String
        zipFileName = sourceFolder & file

        ' Check if the file path is valid before attempting to extract its contents
        If Len(Dir(zipFileName)) = 0 Then
            MsgBox "Invalid file path: " & zipFileName
            Exit Sub
        End If

        'Extract: Unzip all Files to Folder
        Set objZipItems = wShApp.Namespace(zipFileName).Items
        wShApp.Namespace(destinationFolder).CopyHere objZipItems

        'Move to the next file
        file = Dir
    Loop

    MsgBox "All ZIP files extracted successfully."
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Solved i use this

and change to fix my without using references :)
 
Upvote 0
Solution

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top