Add Underline to Font Using Macro

Dear all,

I would like to create a module that I can call to change the properties of a style. Below you can see the code.

The idea is simple: when I specify a color, I would also like it to be underlined. If I do not specify a color, I would like to remove the underlining.

The code works for changing the text color but not the underlining, does someone know how to do this? Why does the code work for the color but not the underlining?
image

Kind regards
Researcher10

The CharUnderline property has an integer type. Its possible meanings are given here.

Thank you so much for looking into it, my knowledge of this subject is really limited but I would like to get this thing up and running.

So if I change it to a number, if I understood your comment correctly, it still does not work.
image

Please upload an example file. Then we can watch it together.

I just made a test document to upload and used the exact same code and it works! Hmmm, not sure why it doesn’t in the actual document. I’ll get back to this when I have a better idea of where the problem is located. Thank you very much for now and I’ll edited this post when it is resolved.

Correction: The solution I posted earlier was incorrect.
The solution actually ended up simply being that I had to reassign the style to the words I wanted to edit. This updated it and made it possible for the macro to correctly change the properties of the style again

Many thanks to sokol92 for his help!