Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sub WorksheetSizes()
'Update 20140526
Dim xWs As Worksheet
Dim Rng As Range
Dim xOutWs As Worksheet
Dim xOutFile As String
Dim xOutName As String
xOutName = "Hoc Excel Online"
xOutFile = ThisWorkbook.Path & "\TempWb.xls"
On Error Resume Next
Application.DisplayAlerts = False
Err = 0
Set xOutWs = Application.Worksheets(xOutName)
If Err = 0 Then
xOutWs.Delete
Err = 0
End If
With Application.ActiveWorkbook.Worksheets.Add(Before:=Application.Worksheets(1))
.Name = xOutName
.Range("A1").Resize(1, 2).Value = Array("Worksheet Name", "Size")
End With
Set xOutWs = Application.Worksheets(xOutName)
Application.ScreenUpdating = False
xIndex = 1
For Each xWs In Application.ActiveWorkbook.Worksheets
If xWs.Name <> xOutName Then
xWs.Copy
Application.ActiveWorkbook.SaveAs xOutFile
Application.ActiveWorkbook.Close SaveChanges:=False
Set Rng = xOutWs.Range("A1").Offset(xIndex, 0)
Rng.Resize(1, 2).Value = Array(xWs.Name, VBA.FileLen(xOutFile))
Kill xOutFile
xIndex = xIndex + 1
End If
Next
Application.ScreenUpdating = True
Application.Application.DisplayAlerts = True
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment