问题:
有的Excel工作簿内含有很多无用的表格格式(如下图)需要删除,以方便操作和减小文件大小。可是Excel普通界面只能一个个选中删除,实在太低效。
万能的VBA,能不能一键批量删除无用的表格格式?
当然可以。先看下效果。
VBA程序效果:
Talk is cheap, show me the code.
VBA程序源码:
Sub deleteUnusedCustomTableStyles() 'v 0.1 '2024-05-27 'ExcelVBA持续超越@头条 jeffreyjcli-at-qq.com
On Error Resume Next
With ActiveWorkbook
DateTime0 = Timer
sDefaultTableStyle = .DefaultTableStyle
For ii = .TableStyles.Count To 1 Step -1
If Not .TableStyles(ii).BuiltIn And .TableStyles(ii) <> sDefaultTableStyle Then
.TableStyles(ii).Delete
If Err.Number = 0 Then
lDeleted = lDeleted + 1
Else
Err.Clear
End If
End If
Next
DateTime1 = Timer
End With
If Not IsEmpty(lDeleted) Then
MsgBox "完成!已删除: " & lDeleted & " 个未使用的表格格式。" & vbCrLf & _
"用时:" & Round(DateTime1 - DateTime0, 3) & " 秒."
Else
MsgBox "无表格格式可以删除。"
End If
End Sub
PS:
如果需要批量处理多个工作簿,或者需要插件随时在任意工作簿一键运行的话,可以私信我。
OK. 分享完毕。感谢您的关注、点赞、收藏与点评。下期见~
#Excel##职场excel小技巧##excel##Excel技巧#
《Excel VBA 从入门到封神系列之进阶篇》:Excel工作簿大瘦身:一键批量删除无用的表格格式