ASKER
ASKER
Option Explicit
Sub Legend_ShowNoShow_v3()
Dim wb As Workbook
Dim chtObj As ChartObject
Dim ChtDefinedName As String
Dim ChtDefinedNameVal As String
Set wb = ActiveWorkbook
For Each chtObj In ActiveSheet.ChartObjects
With chtObj.Chart
ChtDefinedName = "OriLegendFont_" & .Parent.Name
If .HasLegend Then
'I don't normally use on error resume next, but in my brief testing it worked for this example (for the situations where the Named Range didn't exist
On Error Resume Next
wb.Names(ChtDefinedName).Delete
On Error GoTo 0
''if you don't want to see the Named Ranges in the excel 2007 Name Manager you can use the next line...
'wb.Names.Add Name:=ChtDefinedName, Visible:=False, RefersTo:=.Legend.Font.Name
''if you do want to see the defined names use this version...
wb.Names.Add Name:=ChtDefinedName, Visible:=True, RefersTo:=.Legend.Font.Name
.HasLegend = False
Else
.HasLegend = True
With .Legend
.IncludeInLayout = True
ChtDefinedNameVal = wb.Names(ChtDefinedName).Value
.Font.Name = Mid(ChtDefinedNameVal, 3, Len(ChtDefinedNameVal) - 3)
End With
End If
'code from v2
' .HasLegend = Not .HasLegend
' If .HasLegend Then
' With .Legend
' .IncludeInLayout = True
' .Font.Name = "Verdana"
' End With
' End If
End With
Next chtObj
MsgBox "done", vbOKOnly + vbInformation, "MACRO COMPLETE"
'free memory
Set wb = Nothing
End Sub
ASKER
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
TRUSTED BY