VBA To Check Worksheet Size 2
VBA To Check Worksheet Size 2
1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for
Applications window.
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