Within an UDF: dormatting a cell only to numeric when the formatting is timestamp ( and vice versa )

13 views
Skip to first unread message

Guido De Bouver

unread,
Feb 19, 2026, 6:43:00 AM (4 days ago) Feb 19
to Excel-DNA
Hello all,

I have a large set of UDF's that request data from external webservices.
In some conditions, the UDF also updates the data format using the below
ExcelAsyncUtil.QueueAsMacro(
        Sub()
            Try : xlapp.Range(XlCall.Excel(XlCall.xlfReftext, c, True)).NumberFormat = defaultrealformat
            Catch ex As Exception
            End Try
        End Sub)

Now the problem is that this formatting does not go well with the user providing a different format as my number format overrides the user's selection.

I was wondering if the UDF can findout the format of a range - so I could for example only format to a number if a timeformat was applied.

But of course, a range has multiple cells, so there might be different formats applied...

Any ideas ? Thanks in advance


Guido De Bouver

unread,
Feb 19, 2026, 7:59:02 AM (4 days ago) Feb 19
to Excel-DNA
fyi, I am currently using the below in my UDF, but throws me an error consistenly on the XlCall

Dim c = CType(XlCall.Excel(XlCall.xlfCaller), ExcelReference)
Dim topLeft As New ExcelReference(c.RowFirst, c.RowFirst, c.ColumnFirst, c.ColumnFirst, c.SheetId)
XlCall.Excel(XlCall.xlfGetCell, 49, topLeft)
Reply all
Reply to author
Forward
0 new messages