Here is a pair of User Defined Functions that I use at times while developing (overly) long cell formulas. They work a little like the Current() function so I can develop cases that otherwise require repeating long formula sub-components without repeating them until I have things working.
It is wrong and twisted to use these for the OQ intent, it is slow, and who knows what could happen. But, it…technically…works.
Here are the UDF’s:
Function Peek(Optional Address As Variant, Optional Pop As Boolean)
Dim NamedRanges as Object
Dim Content As Variant
NamedRanges = ThisComponent.NamedRanges
If IsMissing(Address) Then
Address = "__X__"
Else
Address = "__" & Address 'Use a mini namespace
End If
If NamedRanges.hasByName(Address) Then
Content = NamedRanges.getByName(Address).Content
If VarType(Content) = 8 Then
If Left(Content, 1) = """" and Right(Content, 1) = """" Then
Content = Mid(Content, 2, Len(Content) - 2) 'Remove protective quotes
End If
Else
'NOP
End If
Peek = Content
If Not IsMissing(Pop) Then
'If Pop Then NamedRanges.removeByName(Address)
End If
End If
End Function
Function Poke(Content As Variant, Optional Address As Variant)
Dim NamedRanges As Object
Dim CellPos As New com.sun.star.table.CellAddress
NamedRanges = ThisComponent.NamedRanges
If IsMissing(Address) Then
Address = "__X__"
Else
Address = "__" & Address 'Use a mini namespace
End If
Poke = Content 'Chain back as is before prep for UNO storage
Content = """" & Content & """" 'Protect from UNO converting to lower case
If NamedRanges.hasByName(Address) Then
NamedRanges.getByName(Address).setContent(Content)
Else
NamedRanges.addNewByName(Address, Content, CellPos, 0)
End If
End Function
For the use of these we have:
Please, understand that this is purely academic!
(BTW the Pop option doesn’t work in Peek.)