簡體   English   中英

VBA宏幫助-從Excel 2016清除表和單元格格式

[英]VBA Macro Help - Clear Table and Cell Formatting from Excel 2016

我正在嘗試從整個工作簿中清除所有表格式和單元格格式。 這段代碼可以幫助我解決大部分問題,但是我不想清除單元格內容。

我嘗試通過刪除Selection.ClearContents字符串來修改此行為。 但是,這會使代碼不起作用。

任何幫助將不勝感激。

謝謝!

Sub ClearAll()

    Set wbook = ActiveWorkbook

    For Each sht In wbook.Worksheets
       sht.Activate
       sht.Cells.Select
       Selection.ClearContents
       Selection.ClearFormats ' edit: clear formats too
       sht.Cells(1, 1).Select ' edit: select the first cell to cancel selection of the whole sheet
    Next sht


End Sub

不知道您所說的非功能性是什么。 無論如何,您無需選擇或激活任何內容。

Sub ClearAll()

Dim sht As Worksheet, wbook As Workbook, t As ListObject

Set wbook = ActiveWorkbook

For Each sht In wbook.Worksheets
    For Each t In sht.ListObjects
        t.Unlist
    Next t
    sht.Cells.ClearFormats
Next sht

End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM