使用 VBA 从整个工作表中删除格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20833378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:29:48  来源:igfitidea点击:

Removing Formats From Entire Worksheet with VBA

vbaexcel-vbaexcel

提问by Behseini

Using VBA, I am trying to Clear all Formats all entire of the active Worksheet.

使用 VBA,我试图清除所有活动工作表的所有格式。

Dim ws As Worksheet
 Set ws = ThisWorkbook.ActiveSheet
 With ws
           .ClearFormats
 End With

But I am getting following error:

但我收到以下错误:

enter image description here

在此处输入图片说明

However using the same code with .UsedRange works fine as:

但是,使用与 .UsedRange 相同的代码可以正常工作:

With .UsedRange
    .ClearFormats
End With

Can you please let me know how fix this to format entire sheet!

您能否让我知道如何解决此问题以格式化整个工作表!

回答by chris neilsen

ClearFormatsis a method of a Range, wereas ActiveSheetis a Worksheet

ClearFormats是 a 的方法Range,areasActiveSheet是 aWorksheet

You could use

你可以用

ThisWorkbook.ActiveSheet.Cells.ClearFormats

(Cellsis a range of all the cells on a worksheet)

Cells是工作表上所有单元格的范围)