View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Modifying a Defined Name's Contents

Ron,
Here's a procedure I use for wks UI settings. The procedure retrieves
UI settings that are stored in local defined names for each wks. It
should give you enough of an idea to get you where you want to go.

(Watch for line wraps)

'Defined names used for DEFAULT UI Settings
Private Const msUI_SETTINGS As String = "uiProgRows,uiProgCols," _
& "uiScrollArea,uiSelect," _
& "uiFilter,uiOutline," _
& "uiOutlineR,uiOutlineC," _
& "uiRowColHdrs,uiProtect," _
& "uiIsSet,uiVisible"


Sub Setup_WksUI(Optional Wks As Worksheet)
Dim sz As String
Dim vSetting, vSettings
Dim i As Integer

If Wks Is Nothing Then Set Wks = ActiveSheet

vSettings = Split(msUI_SETTINGS, ",")

'The sheet must be visible and not protected to do this
Wks.Unprotect PWRD
Wks.Visible = xlSheetVisible

For i = LBound(vSettings) To UBound(vSettings)
'Determine if the current sheet requires the current setting
vSetting = Empty
On Error Resume Next
If vSettings(i) = "uiScrollArea" Then '//it's a range object
Set vSetting = Application.Evaluate("'" & Wks.name _
& "'!" & vSettings(i))
Else '//it's a stored value
vSetting = Wks.Names(vSettings(i)).RefersTo
If Not (vSetting = Empty) Then _
vSetting = Application.Evaluate("'" & Wks.name _
& "'!" & vSettings(i))
End If 'rngCell.Value = "uiScrollArea"
On Error GoTo 0

If Not IsEmpty(vSetting) Then
Select Case vSettings(i)
Case "uiProgRows"
If vSetting 0 Then _
Wks.Range("A1").Resize(vSetting).EntireRow.Hidden = True
Case "uiProgCols"
If vSetting 0 Then _
Wks.Range("A1").Resize(, vSetting).EntireColumn.Hidden =
True
Case "uiScrollArea": Wks.ScrollArea = vSetting.address
Case "uiSelect": Wks.EnableSelection = vSetting
Case "uiFilter": Wks.EnableAutoFilter = vSetting
Case "uiRowColHdrs"
Wks.Activate: _
Application.ActiveWindow.DisplayHeadings = vSetting
Case "uiProtect": If vSetting Then wksProtect Wks.name
Case "uiVisible": Wks.Visible = vSetting
Case "uiOutline": Wks.EnableOutlining = vSetting

'Persist any changes the user makes during runtime
Case "uiOutlineR"
If Application.Evaluate("'" & Wks.name _
& "'!" & "uiSet") = 0 Then _
Wks.Outline.ShowLevels RowLevels:=vSetting: _
Wks.Names("uiSet").RefersTo = "=1"
Case "uiOutlineC"
If Application.Evaluate("'" & Wks.name _
& "'!" & "uiSet") = 0 Then _
Wks.Outline.ShowLevels ColumnLevels:=vSetting: _
Wks.Names("uiSet").RefersTo = "=1"
End Select 'Case vSettings(i)
End If 'Not IsEmpty(vSetting)
Next
End Sub 'Setup_WksUI()

**Note that the last 2 Select Case conditions don't work if both rows
AND columns have Outline levels. Since I most always do one OR the
other, I didn't account for both. In that scenario, "uiOutlineC" will
never happen without modifying this procedure.

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc