each WorksheetSizes

Seesee

New Member
Joined
Apr 5, 2023
Messages
8
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Hi,
Appear the error message : "1004 cannot copy the sheet" when run the below vba coding, please help to fix.
1680746870167.png

Sub WorksheetSizes()
Dim wks As Worksheet
Dim c As Range
Dim sFullFile As String
Dim sReport As String
Dim sWBName As String
sReport = "Size Report"
sWBName = "Erase Me.xls"
sFullFile = ThisWorkbook.path & _
Application.PathSeparator & sWBName
' Add new worksheet to record sizes
On Error Resume Next
Set wks = Worksheets(sReport)
If wks Is Nothing Then
With ThisWorkbook.Worksheets.Add(Before:=Worksheets(1))
.Name = sReport
.Range("A1").Value = "Worksheet Name"
.Range("B1").Value = "Approximate Size (kb)"
End With
End If
On Error GoTo 0
With ThisWorkbook.Worksheets(sReport)
.Select
.Range("A1").CurrentRegion.Offset(1, 0).ClearContents
Set c = .Range("A2")
End With
Application.ScreenUpdating = False
' Loop through worksheets
For Each wks In ActiveWorkbook.Worksheets
If wks.Name <> sReport Then
wks.Copy
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs sFullFile
ActiveWorkbook.Close SaveChanges:=False
Application.DisplayAlerts = True
c.Offset(0, 0).Value = wks.Name
c.Offset(0, 1).Value = Format(FileLen(sFullFile) / 1000, "#,##0.00")
Set c = c.Offset(1, 0)
Kill sFullFile
End If
Next wks
Range("a1:b1").WrapText = True
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Are there hidden sheets in the workbook ? This can cause the error
 
Upvote 0
Are there hidden sheets in the workbook ? This can cause the error
Hi,
Thanks for your prompt reply. If keep invisible sheets, could you amend the coding to get same result. Thanks.
 
Upvote 0
You will have to unhide / hide the wks, like this
So after the for each line
VBA Code:
For Each wks In Worksheets
wks.Visible = true


And then before the Next wks

VBA Code:
wks.Visible =false
Next wks
 
Upvote 0
Solution
….1st pop-up:show macro is not found and 2nd pop-up:show worksheet is not ready for copy successfully ….could you help me please🙄
 
Upvote 0
How are you activating the macro?
Where is the macro located, module, worksheet, ??
 
Upvote 0
Good morning Michael
In vbe edtitor press F5 to execute a macro, the marco is in the same module under an excel project only…..
I try this code to execute by another desktop, it is okay…whether the excel file is got the virus😨
 
Upvote 0
1680837911927.png

Hi Michael,
How steps to make a screen capture ‘VBA Code:’ share with everyone?
Thank you for your teaching🙏
 
Upvote 0

Forum statistics

Threads
1,215,178
Messages
6,123,484
Members
449,100
Latest member
sktz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top