dexiongmao, in my opinion, the code execution time can be significantly shortened.
Notice:
1. When no characters in Cell are bold, Cell.Font.Bold returns False.
2. When all characters are bold, Cell.Font.Bold returns True.
3. When some characters are bold, Cell.Font.Bold returns Null.
With this knowledge, you can speed up the execution of the code when the second condition is met, because we know that the whole string from 1 to Len(Cell.Value) should be bold. If the third condition is met, you can also speed up the code. Do not change sign by sign, but search and change entire fragments (reading a property itself is several times faster than changing this property). You read many times but only change once.
By following the above rules, I think that the code execution time can be reduced by at least half.
I don't like the following code, but let it be an inspiration to optimize your code.
In my tests, I got a performance increase of 2-3 times (and even 6 to 13, depending on the complexity of the input texts). So it's probably worth fighting for.
Artik
Bookmarks