Change Font from returne value of UDF in VBA using Range.Characters property

删除回忆录丶 提交于 2020-12-27 06:32:45

问题


I've written a user defined function and want to change the font format of a defined character range, of the return value.

It doesn´t seem to work the way i expekt, for cells with functions "= ..." . I only got 2 scenarios, first formated the whole return value and second doesn't format anything. For "normal" cells, is works, as you can see in the screenshot.

try to change font format of first char to purple: top cell with function, botton cell without function:

Anyone have an idea, how to do it correctly?

Iam thankful about every answer / hint i can get! Greetings Leo

Edit 03.12.2020 Thank you for all your answers and hints, some of you asked for code, here it is:

Public Function format(val As String)

With Application.Caller
 .Characters(1, 1).Font.Color = RGB(255, 0, 255)
End With

With Application.Caller.Offset(1, 0)
 .Characters(1, 1).Font.Color = RGB(255, 0, 255)
End With

format = val

End Function

So if you type some chars manually under the "function cell", for example "abcd", you should get following result (screenshot)

Top before running function, bottom after running function:

来源:https://stackoverflow.com/questions/65110841/change-font-from-returne-value-of-udf-in-vba-using-range-characters-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!