Làm giảm dung lượng tập tin Excel

[ 2011-09-18 17:52:32 | Tác giả: Admin ]

Sau 5 phút web sẽ chạy quảng cáo 1 lần, và chỉ hiện 5 lần trong ngày. Các bạn chịu khó nhấn Skip Ad khi quảng cáo hiễn thị như 1 cách giúp duy trì Web
Cỡ chữ: Lớn | Bình thường | Nhỏ
Hãy Click +1 để ủng hộ Blog của La Chí Nhân

http://www.vbaexpress.com/forum/images/logos/09-18.gif


Sau khi sử dụng một thời gian, các bạn phát hiện tập tin Excel của mình có dung lượng lớn. Vậy làm sao để làm giảm dung lượng tập tin Excel này?
Xin giới thiệu các bạn đoạn code của DRJ
Option Explicit
 
Sub ExcelDiet()
 
 Dim j As Long
 Dim k As Long
 Dim LastRow As Long
 Dim LastCol As Long
 Dim ColFormula As Range
 Dim RowFormula As Range
 Dim ColValue As Range
 Dim RowValue As Range
 Dim Shp As Shape
 Dim ws As Worksheet
 
 Application.ScreenUpdating = False
 Application.DisplayAlerts = False
 
 On Error Resume Next
 
 For Each ws In Worksheets
 With ws
 ' Tìm ô sử dụng cuối cùng với công thức và giá trị
 ' Tìm theo cột và hàng
 On Error Resume Next
 Set ColFormula = .Cells.Find(What:="*", After:=Range("A1"), LookIn:=xlFormulas, _
 LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious)
 Set ColValue = .Cells.Find(What:="*", After:=Range("A1"), LookIn:=xlValues, _
 LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious)
 Set RowFormula = .Cells.Find(What:="*", After:=Range("A1"), LookIn:=xlFormulas, _
 LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
 Set RowValue = .Cells.Find(What:="*", After:=Range("A1"), LookIn:=xlValues, _
 LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
 On Error Goto 0
 
 ' Xác định cột cuối cùng
 If ColFormula Is Nothing Then
 LastCol = 0
 Else
 LastCol = ColFormula.Column
 End If
 If Not ColValue Is Nothing Then
 LastCol = Application.WorksheetFunction.Max(LastCol, ColValue.Column)
 End If
 
 ' Xác định hàng cuối
 If RowFormula Is Nothing Then
 LastRow = 0
 Else
 LastRow = RowFormula.Row
 End If
 If Not RowValue Is Nothing Then
 LastRow = Application.WorksheetFunction.Max(LastRow, RowValue.Row)
 End If
 
 ' Xác định xem có shapes nào nằm ngoài hàng cuối và cột cuối
 For Each Shp In .Shapes
 j = 0
 k = 0
 On Error Resume Next
 j = Shp.TopLeftCell.Row
 k = Shp.TopLeftCell.Column
 On Error Goto 0
 If j > 0 And k > 0 Then
 Do Until .Cells(j, k).Top > Shp.Top + Shp.Height
 j = j + 1
 Loop
 If j > LastRow Then
 LastRow = j
 End If
 Do Until .Cells(j, k).Left > Shp.Left + Shp.Width
 k = k + 1
 Loop
 If k > LastCol Then
 LastCol = k
 End If
 End If
 Next
 
 .Range(Cells(1, LastCol + 1).Address & ":IV65536").Delete
 .Range(Cells(LastRow + 1, 1).Address & ":IV65536").Delete
 End With
 Next
 
 Application.ScreenUpdating = True
 Application.DisplayAlerts = True
 
End Sub

Xin chú ý: các bạn phải UnHide các sheet trước khi thực hiện thủ tục này.

Nguồn: http://www.giaiphapexcel.com/forum/showthread.php?51098-L%C3%A0m-gi%E1%BA%A3m-dung-l%C6%B0%E1%BB%A3ng-t%E1%BA%ADp-tin-Excel
http://www.vbaexpress.com/kb/getarticle.php?kb_id=83
Tham khảo thêm

QUYÊN GÓP DUY TRÌ WEBSITE

Ghé thăm tôitrên
[Được sửa bởi Admin, lúc 2011-09-18 17:56:22]
Click +1 để ủng hộ Blog của La Chí Nhân, Click Cảm ơn nếu bài viết hữu ích


Comments Feed Comments Feed: http://trubatgioi.net/lbs/feed.asp?q=comment&id=272
UTF-8 Encoding Trackback URL: http://trubatgioi.net/lbs/trackback.asp?id=272

Không có lời bình nào cho bài viết này.

Gởi Ý Kiến
Hình vui
[smile] [confused] [cool] [cry]
[eek] [angry] [wink] [sweat]
[lol] [stun] [razz] [redface]
[rolleyes] [sad] [yes] [no]
[heart] [star] [music] [idea]
Mở UBB Codes
Auto Convert URL
Show Smilies
Hidden Comment
Tài khoản:   Mật khẩu:   Đăng Ký?
Mã bảo vệ * Điền mã bảo vệ vào ô