Sto cercando di ridurre le dimensioni del file di una cartella di lavoro di Excel che sto utilizzando. So già che le righe non utilizzate sono un problema e immagini non necessarie, ecc. Il mistero è perché c'è una parte segreta di Excel che sembra solo crescere?Cosa va nell'oggetto cartella di lavoro di Excel che aumenta le dimensioni del file?
posso scoprire la dimensione totale di tutta la mia documento con
Sub workbook_objectsize()
With CreateObject("Scripting.FileSystemObject")
Set wb = ActiveWorkbook
WBObjectSize = .GetFile(wb.fullname).Size
MsgBox (Format(WBObjectSize, "#,##0") & " Bytes")
End With
End Sub
e mi può scoprire la dimensione per foglio e l'Oggetto WB usando
Sub GetSheetSizes()
' ZVI:2012-05-18 Excel VBA File Size by Worksheet in File
' CAR:2014-10-07 Enhanced to take hidden and very hidden sheets into account
Dim a() As Variant
Dim Bytes As Double
Dim i As Long
Dim fileNameTmp As String
Dim wb As Workbook
Dim visState As Integer
Set wb = ActiveWorkbook
ReDim a(0 To wb.Sheets.Count, 1 To 2)
' Turn off screen updating
Application.ScreenUpdating = False
On Error GoTo exit_
' Put names into a(,1) and sizes into a(,2)
With CreateObject("Scripting.FileSystemObject")
' Build the temporary file name
Err.Clear
fileNameTmp = .GetSpecialFolder(2) & "\" & wb.Name & ".TMP"
' Put workbook's name and size into a(0,)
a(0, 1) = wb.Name
a(0, 2) = .GetFile(wb.fullname).Size
' Put each sheet name and its size into a(i,)
For i = 1 To wb.Sheets.Count
visState = wb.Sheets(i).Visible
wb.Sheets(i).Visible = -1 ' Show sheet long enough to copy it
DoEvents
wb.Sheets(i).Copy
ActiveWorkbook.SaveCopyAs fileNameTmp
wb.Sheets(i).Visible = visState
a(i, 1) = wb.Sheets(i).Name
a(i, 2) = .GetFile(fileNameTmp).Size
Bytes = Bytes + a(i, 2)
ActiveWorkbook.Close False
Next
Kill fileNameTmp
End With
' Show workbook's name & size
Debug.Print a(0, 1), Format(a(0, 2), "#,##0") & " Bytes"
' Show workbook object's size
Debug.Print "Wb Object", Format(a(0, 2) - Bytes, "#,##0") & " Bytes"
' Show each sheet name and its size
For i = 1 To UBound(a)
Debug.Print a(i, 1), Format(a(i, 2), "#,##0") & " Bytes"
Next
exit_:
' Restore screen updating
Application.ScreenUpdating = True
' Show the reason of error if happened
If Err Then MsgBox Err.Description, vbCritical, "Error"
End Sub
Ecco l'esercizio. Ho MyWorkbook
passo 1. controllo le dimensioni del file totale e la dimensione del file da scheda + oggetto wb
MYWORKBOOK Ver0.34 test.xlsm 932,450 Bytes Total
Wb Object 201,679 Bytes
Home 312,904 Bytes
NISI_DETAIL 40,815 Bytes
DATABASE 49,186 Bytes
Settings 13,690 Bytes
NISI_LIST 27,484 Bytes
PleaseWait 21,232 Bytes
success 22,077 Bytes
Brands 34,721 Bytes
USER_LIST 26,819 Bytes
QUERY_LIST 37,880 Bytes
CAT_MAN_TOOLS 88,406 Bytes
Sheet1 9,997 Bytes
PROMO_LIST 45,560 Bytes
passaggio 2. eliminare tutti SCHEDE lasciando solo un nuovo sheet1 vuoto e controllare di nuovo
MYWORKBOOK Ver0.34 test .xlsm 370,052 Bytes
Wb Object 361,589 Bytes
Sheet1 8,463 Bytes
Sì, la dimensione del file è stata ridotta ma questo perché ho eliminato ogni foglio. Tuttavia, questo misterioso oggetto Wb è diventato più grande. Che diavolo??? nient'altro che un singolo foglio bianco e un file 370Kb ????? BTW esegue questo stesso test su una nuova cartella di lavoro yeilds una dimensione dell'oggetto Wb di 0 byte.
TL; DR: Cosa diavolo è l'oggetto Wb nell'esempio sopra riportato? Perché continua a crescere? Come posso ridurlo a 0 byte?
Grande domanda e ricerche interessanti per sostenerlo! Sfortunatamente, ho la sensazione che sarà chiuso come OT. :( – FreeMan
cosa è OT? Spero che non sia chiuso, ho davvero bisogno di una risposta a questo.Io ho cercato su tutto il web –
OT = Off topic. Dal momento che non è legato alla programmazione o al codice, alcuni possono votare per chiudere Sarei affascinato nel trovarti anche per questo: – FreeMan