|
本帖最后由 客非 于 2024-5-21 15:47 编辑
因为工作需要,我做了一个宏,用于按字符把某些颜色的字符替换成另一个颜色。但是有一些单元格,在执行宏的时候,会导致整个单元格的font大变样
。
我摘了一个会大变样的单元格出来,B2的是原本的样子,B9是直接点击replace之后的样子,B8是双击单元格进入编辑模式之后,再退出选中单元格,点击replace的样子。执行顺序:B9>B8。可以看出,即便是大变样,他还会变得不一样。
我尝试了百度和问AI,都没给出解决办法。问Llama3,它认为是缓存问题,但是给出的解决办法解决不了问题。
请问各位大佬这个问题要怎么解决?
‘以下回答来自Llama3
A tricky Excel macro issue! 😅
The behavior you're describing is likely due to the way Excel handles character formatting in cells. When you iterate through each character in a cell using VBA, Excel may not always behave as expected, especially when it comes to formatting.
Here are a few possible reasons why your macro might not be working as intended:
1.Character formatting is not explicitly set: When you iterate through each character, Excel may not retain the original formatting of the character. Instead, it may apply the default formatting of the cell or the formatting of the first character in the cell.
2.Excel's internal formatting cache: Excel has an internal cache that stores formatting information for cells. When you make changes to character formatting using VBA, Excel may not always update this cache correctly, leading to unexpected behavior.
3.VBA's character iteration is not always reliable: VBA's Characters object, which is used to iterate through each character in a cell, may not always return the correct character or formatting information.
|
|