Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3113|回复: 12

[已解决]批量删除没进行过打印设置的工作表

[复制链接]
发表于 2016-11-21 10:04 | 显示全部楼层 |阅读模式
一个工作簿中有很多张工作表,有些工作表有打印设置,有些没有,有打印设置的工作表要保留,其他的全部删除,就是根据是否进行过打印设置来判断要不要删除,请问各位大师这个用VBA怎么实现?
最佳答案
2016-11-22 08:53
Sub test4()
    Dim sh As Worksheet
    Application.DisplayAlerts = False
    For Each sh In Sheets
        If sh.PageSetup.PrintArea <> "" Then sh.Delete
    Next
End Sub
发表于 2016-11-21 10:55 | 显示全部楼层
Sub test()
    Dim sh As Worksheet
    Application.DisplayAlerts = False
    For Each sh In Sheets
        Debug.Print sh.Name, isDefault(sh)
'        If isDefault(sh) = False Then sh.Delete
    Next
End Sub

Function isDefault(sh) As Boolean
    Dim x As Boolean
    x = True
    With sh.PageSetup
        x = x And .AlignMarginsHeaderFooter = True
        x = x And .BlackAndWhite = False
        x = x And .BottomMargin = Application.InchesToPoints(0.75)
        x = x And .CenterFooter = ""
        x = x And .CenterHeader = ""
        x = x And .CenterHorizontally = False
        x = x And .CenterVertically = False
        x = x And .DifferentFirstPageHeaderFooter = False
        x = x And .Draft = False
        x = x And .EvenPage.CenterFooter.Text = ""
        x = x And .EvenPage.CenterHeader.Text = ""
        x = x And .EvenPage.LeftFooter.Text = ""
        x = x And .EvenPage.LeftHeader.Text = ""
        x = x And .EvenPage.RightFooter.Text = ""
        x = x And .EvenPage.RightHeader.Text = ""
        x = x And .FirstPage.CenterFooter.Text = ""
        x = x And .FirstPage.CenterHeader.Text = ""
        x = x And .FirstPage.LeftFooter.Text = ""
        x = x And .FirstPage.LeftHeader.Text = ""
        x = x And .FirstPage.RightFooter.Text = ""
        x = x And .FirstPage.RightHeader.Text = ""
        x = x And .FirstPageNumber = xlAutomatic
        x = x And .FooterMargin = Application.InchesToPoints(0.3)
        x = x And .HeaderMargin = Application.InchesToPoints(0.3)
        x = x And .LeftFooter = ""
        x = x And .LeftHeader = ""
        x = x And .LeftMargin = Application.InchesToPoints(0.7)
        x = x And .OddAndEvenPagesHeaderFooter = False
        x = x And .Order = xlDownThenOver
        x = x And .Orientation = xlPortrait
        x = x And .PaperSize = xlPaperA4
        x = x And .PrintArea = ""
        x = x And .PrintComments = xlPrintNoComments
        x = x And .PrintErrors = xlPrintErrorsDisplayed
        x = x And .PrintGridlines = False
        x = x And .PrintHeadings = False
        x = x And Join(ActiveSheet.PageSetup.PrintQuality) = "600 600"
        x = x And .PrintTitleColumns = ""
        x = x And .PrintTitleRows = ""
        x = x And .RightFooter = ""
        x = x And .RightHeader = ""
        x = x And .RightMargin = Application.InchesToPoints(0.7)
        x = x And .ScaleWithDocHeaderFooter = True
        x = x And .TopMargin = Application.InchesToPoints(0.75)
        x = x And .Zoom = 100
    End With
    isDefault = x
End Function




先看看判断。
如果是,再启用蓝色那句

回复

使用道具 举报

 楼主| 发表于 2016-11-21 11:25 | 显示全部楼层
回复

使用道具 举报

发表于 2016-11-21 11:31 | 显示全部楼层
把附件发上来看看
回复

使用道具 举报

 楼主| 发表于 2016-11-21 11:45 | 显示全部楼层
本帖最后由 zhaohu800 于 2016-11-21 12:35 编辑

附件已上传,表格太多,只留了几个,请帮忙看一下

2.rar

15.81 KB, 下载次数: 3

回复

使用道具 举报

发表于 2016-11-22 08:34 | 显示全部楼层
QQ截图20161122092135.jpg
3.rar (21.1 KB, 下载次数: 2)
回复

使用道具 举报

 楼主| 发表于 2016-11-22 08:43 | 显示全部楼层
前面三个是需要打印的,不能能删除,就是最后一个含量表这个不需要打印,把这个工作表删除就可以
回复

使用道具 举报

发表于 2016-11-22 08:45 | 显示全部楼层
有些工作表有打印设置,请说明一下这句的具体含义。
即,怎样算有打印设置,怎样不算有打印设置

回复

使用道具 举报

 楼主| 发表于 2016-11-22 08:50 | 显示全部楼层
就是设置过打印区域,前面三个表都有设置过打印区域,最后一个没有设置过打印区域,就这个工作表要删除
回复

使用道具 举报

发表于 2016-11-22 08:53 | 显示全部楼层    本楼为最佳答案   
Sub test4()
    Dim sh As Worksheet
    Application.DisplayAlerts = False
    For Each sh In Sheets
        If sh.PageSetup.PrintArea <> "" Then sh.Delete
    Next
End Sub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-25 04:52 , Processed in 0.398515 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表