Skip to content

Instantly share code, notes, and snippets.

@ndthanh
Created July 22, 2017 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndthanh/2d3f11c6282e66674556c4f086840df1 to your computer and use it in GitHub Desktop.
Save ndthanh/2d3f11c6282e66674556c4f086840df1 to your computer and use it in GitHub Desktop.
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