从Excel工作簿中删除不需要的样式

发布于 2025-02-13 03:37:07 字数 1165 浏览 1 评论 0原文

我的Excel工作簿已达到了Excel风格的限制。我发现了VBA代码以删除未建立的,应用它并发现样式是内置的和“ sapbexstditem*”。

不幸地运行此代码没有效果。大约2周前,大约有36000种样式。 我不知道使用样式。如果我知道它们是如何创建的,我会尝试手动删除该样式,但首选VBA解决方案。

关于彼得

Sub RemoveTheStyles()
 
    Dim style               As style
    Dim l_counter           As Long
    Dim l_total_number      As Long
 
    On Error Resume Next
 
    l_total_number = ActiveWorkbook.Styles.Count
    Application.ScreenUpdating = False
 
    For l_counter = l_total_number To 1 Step -1
    
        Set style = ActiveWorkbook.Styles(l_counter)
        
        If (l_counter Mod 500 = 0) Then
            DoEvents
            Application.StatusBar = "Deleting " & l_total_number - l_counter + 1 & " of " & l_total_number & " " & style.Name
        End If
        
        If Not style.BuiltIn Then style.Delete
        If Left(style.Name, 13) = "SAPBEXstdItem" Then
            style.Delete
        End If
        Debug.Print style.Name
    Next l_counter
 
    Application.ScreenUpdating = True
    Application.StatusBar = False
    Debug.Print "READY!"
    
    On Error GoTo 0
End Sub  

My excel workbook has come upon a limit for excel Styles. I found VBA code to RemoveTheStyles that were not BuiltIn, applied it and found the Styles were BuiltIn and "SAPBEXstdItem*".

Running this code sadly had no effect. There are approx 36000 styles that got added about 2 weeks ago.
I don't know the styles were applied. If I knew how they were created I would try and remove the Style manually but a VBA solution would be preferred.

Regards Peter

Sub RemoveTheStyles()
 
    Dim style               As style
    Dim l_counter           As Long
    Dim l_total_number      As Long
 
    On Error Resume Next
 
    l_total_number = ActiveWorkbook.Styles.Count
    Application.ScreenUpdating = False
 
    For l_counter = l_total_number To 1 Step -1
    
        Set style = ActiveWorkbook.Styles(l_counter)
        
        If (l_counter Mod 500 = 0) Then
            DoEvents
            Application.StatusBar = "Deleting " & l_total_number - l_counter + 1 & " of " & l_total_number & " " & style.Name
        End If
        
        If Not style.BuiltIn Then style.Delete
        If Left(style.Name, 13) = "SAPBEXstdItem" Then
            style.Delete
        End If
        Debug.Print style.Name
    Next l_counter
 
    Application.ScreenUpdating = True
    Application.StatusBar = False
    Debug.Print "READY!"
    
    On Error GoTo 0
End Sub  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沫雨熙 2025-02-20 03:37:08

您不应将样式作为变量名称之类的代码单词使用。

这对我有用

Dim sty As Style  '-- don't use style as variable name
For Each sty In ThisWorkbook.Styles
    If sty.BuiltIn = false then 
        sty.delete
    ElseIf sty.Name Like "SAPBEX*" Then 
        sty.delete
    End If
Next

You shouldn't use a code word like style as variable name.

This works for me

Dim sty As Style  '-- don't use style as variable name
For Each sty In ThisWorkbook.Styles
    If sty.BuiltIn = false then 
        sty.delete
    ElseIf sty.Name Like "SAPBEX*" Then 
        sty.delete
    End If
Next

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文