Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

VBA To Check Worksheet Size 2

This document provides VBA code to get the size of each worksheet in a workbook. The code inserts a new worksheet that lists each existing worksheet's name and file size in bits. To use it, copy and paste the code into a VBA module, then run it by pressing F5. This will create a new worksheet displaying the name and size of each worksheet.

Uploaded by

samuel3sukmana
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

VBA To Check Worksheet Size 2

This document provides VBA code to get the size of each worksheet in a workbook. The code inserts a new worksheet that lists each existing worksheet's name and file size in bits. To use it, copy and paste the code into a VBA module, then run it by pressing F5. This will create a new worksheet displaying the name and size of each worksheet.

Uploaded by

samuel3sukmana
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

With the following VBA code, you can quickly get the size of each worksheet in your

workbook. Please do as this:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for
Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Check the size of each worksheet in a workbook< /p>

1 Sub WorksheetSizes()
'Update 20140526
2
Dim xWs As Worksheet
3 Dim Rng As Range
4 Dim xOutWs As Worksheet
5 Dim xOutFile As String
6 Dim xOutName As String
xOutName = "KutoolsforExcel"
7 xOutFile = ThisWorkbook.Path & "\TempWb.xls"
8 On Error Resume Next
9 Application.DisplayAlerts = False
10 Err = 0
11 Set xOutWs = Application.Worksheets(xOutName)
If Err = 0 Then
12     xOutWs.Delete
13     Err = 0
14 End If
15 With Application.ActiveWorkbook.Worksheets.Add(Before:=Application.Worksheets(1))
    .Name = xOutName
16     .Range("A1").Resize(1, 2).Value = Array("Worksheet Name", "Size")
17 End With
18 Set xOutWs = Application.Worksheets(xOutName)
19 Application.ScreenUpdating = False
20 xIndex = 1
For Each xWs In Application.ActiveWorkbook.Worksheets
21     If xWs.Name <> xOutName Then
22         xWs.Copy
23         Application.ActiveWorkbook.SaveAs xOutFile
24         Application.ActiveWorkbook.Close SaveChanges:=False
25         Set Rng = xOutWs.Range("A1").Offset(xIndex, 0)
        Rng.Resize(1, 2).Value = Array(xWs.Name, VBA.FileLen(xOutFile))
26         Kill xOutFile
27         xIndex = xIndex + 1
28     End If
29 Next
Application.ScreenUpdating = True
30 Application.Application.DisplayAlerts = True
31 End Sub
32
33
34
35
36
37
38

3. Then press F5 key to execute this code, and a new worksheet


named KutoolsforExcel will be inserted into the current workbook which contains
each worksheet name and file size, and the unit is Bit. See screenshot:

You might also like