Method 1 – Using Windows Send Command to Zip an Excel File
- Store your Excel file in a suitable location on your computer.
- Select the Excel file and right-click on the mouse.
- From the Context Menu, select the Send to command.
- From the drop-down select the Compressed (zipped) folder option.
- It will make a copy of the Excel file with the extension .zip.
Read More: How to Reduce Excel File Size Without Opening
Method 2 – Renaming File to Zip an Excel File
- Select the Excel file.
- Go to the Home tab in the File Explorer
- Hover down to the Rename tab and click on it.
- Replace the Excel extension with .zip and hit Enter.
- A message box will appear. Choose Yes from the box.
- As a result, your Excel file will be zipped.
Method 3 – Zipping an Excel File with VBA Code
- Go to the Developer tab in the ribbon and click on the Visual Basic command.
- In the Visual Basic tab, click on Insert.
- Select the Module tab.
- A coding module will appear.
- Enter the following code and save the code.
Sub exceltoZipFile(ZipFolder As Variant, FileName As Variant)
'declaring an object
Dim shell_app As Object
'creating an empty zip file
Open FileName For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1
'copying the excel file to the zip file
Set shell_app = CreateObject("Shell.Application")
shell_app.Namespace(FileName).CopyHere shell_app.Namespace(ZipFolder).items
End Sub
Sub zipped()
Call exceltoZipFile("D:\The Office\zip an excel file\", "D:\The Office\zippedfile.zip")
End Sub
VBA Code Breakdown
- Sub exceltoZipFile(ZipFolder As Variant, FileName As Variant): we have named the function exceltoZipFile which has two arguments namely: ZipFolder and FileName, both are Variant
- Dim shell_app As Object: we have declared a variable named shell_app which is an Object.
- Open FileName For Output As #1 Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0) Close #1: we have created an empty zip file. The character in the middle line is an indication for Windows to create an empty file.
- Set shell_app = CreateObject(“Shell.Application”)shell_app.Namespace(FileName).CopyHereshell_app.Namespace(ZipFolder).items : we have copied the files to the empty zip file that we have previously created.
- Call exceltoZipFile(“D:\The Office\zip an excel file\”, “D:\The Office\zippedfile.zip”): we have called the exceltoZipfile function for execution.
- Go to the Run tab and click on it.
- From the drop-down option, select the Run command to run the code.
- The Excel file will be zipped.
Read More: How to Reduce Excel File Size with Macro
Download Practice Workbook
Related Articles
- How to Compress Excel File for Email
- How to Compress Excel File More than 100MB
- How to Compress Excel File to Smaller Size
- How to Reduce Excel File Size with Pictures
- How to Reduce Excel File Size Without Deleting Data
- How to Determine What Is Causing Large Excel File Size
- [Fixed!] Excel File Too Large for No Reason
- How to Reduce Excel File Size by Deleting Blank Rows
<< Go Back to Excel Reduce File Size | Excel Files | Learn Excel
Get FREE Advanced Excel Exercises with Solutions!