Sub Print3()
Dim sht As Worksheet
Dim CurrentSheet As Worksheet
Dim cht As ChartObject
Application.ScreenUpdating = False
Application.EnableEvents = False
Set CurrentSheet = ActiveSheet
For Each sht In ActiveWorkbook.Worksheets
If .Name <> "CHART OVERALL" Or "CHART TL" Or "CHART BL" Or "CHART TR" Or "CHART BR" Then
Else
For Each cht In sht.ChartObjects
cht.Activate
ActiveChart.PrintOut Copies:=1
Next cht
End If
Next sht
CurrentSheet.Activate
Application.EnableEvents = True
End Sub
我似乎无法让这个工作。我已经尝试了很多这种代码的变体,我不确定为什么它不起作用,因为它相当简单。对于我在If语句中命名的每个工作表,我想在这些工作表中打印图表。有什么想法吗?
答案 0 :(得分:1)
您的if语句需要一些工作,还添加了屏幕更新= true ...
ConstraintLayout > CardView > ConstraintLayout > TextView
答案 1 :(得分:1)
所以我修改了一些东西。对于if语句,我认为它一直在为你注册,可能是由于.Name没有得到工作表名称,因此你从来没有进入你的else语句。这是修改后的代码。
Sub Print3()
Dim sht As Worksheet
Dim CurrentSheet As Worksheet
Dim cht As ChartObject
Application.ScreenUpdating = False
Application.EnableEvents = False
Set CurrentSheet = ActiveSheet
For Each sht In ActiveWorkbook.Worksheets
If sht.Name = "CHART OVERALL" Or sht.Name = "CHART TL" Or sht.Name = "CHART BL" Or sht.Name = "CHART TR" Or sht.Name = "CHART BR" Then
For Each cht In sht.ChartObjects
Debug.Print sht.Name
cht.Activate
ActiveChart.PrintOut Copies:=1
Next cht
End If
Next sht
CurrentSheet.Activate
Application.EnableEvents = True
End Sub