Hi all, I am struggling to dynamically change the axis of my chart in a protected worksheet. The code below works fine on an unprotected sheet, but once I protect the sheet the code is not unprotecting the sheet and it stops without error at the line ws.ChartObjects("SUBPlot").Chart.Axes(xlValue).MaximumScale = upper. I am at a loss as to why the unprotect is not working (MsgBox ws.protectionstatus will give "true" before and after unprotect command). Could you please help me figure out what is going wrong here?
Thank you!
Thank you!
VBA Code:
Function ChangeChartAxisMaxScale(upper)
Dim pass As String
pass = "myPassword"
Dim wasProtected As Boolean
Dim ws As Worksheet
Set ws = ThisWorkbook.ActiveSheet
If ws.ProtectionMode Then
ws.Unprotect Password:=pass
wasProtected = True
Else
wasProtected = False
End If
ws.ChartObjects("SUBPlot").Chart.Axes(xlValue).MaximumScale = upper
If wasProtected Then
ws.Unprotect Password:=pass, UserInterfaceOnly:=True, AllowFiltering:=True, DrawingObjects:=True
ws.EnableOutlining = True
Else
End If
End Function