Sub set_color() Dim r As Range, arr For Each r In Range("A:Z") arr = Split(r, ",") r.Interior.Color = RGB(CInt(arr(0)), CInt(arr(1)), CInt(arr(2))) r.Cells.Font.Color = RGB(CInt(arr(0)), CInt(arr(1)), CInt(arr(2))) Next End Sub报错 1004 本工作薄不能再使用其他新的字体。请关闭其他文档,再试一次
时间: 2023-08-03 20:09:30 浏览: 28
这个错误是因为你打开了其他的Excel文档,其中的某一个文档正在使用一个新的字体,而你的代码尝试在当前工作簿中使用该字体,所以会出现此错误。解决方法有两种:
1.关闭所有其他的Excel文档,只保留当前正在使用的文档,然后重新运行你的代码。
2.在你的代码中添加一行代码,指定使用默认字体。例如:
```
Sub set_color()
Dim r As Range, arr
Application.ScreenUpdating = False '关闭屏幕刷新
For Each r In Range("A:Z")
arr = Split(r, ",")
r.Interior.Color = RGB(CInt(arr(0)), CInt(arr(1)), CInt(arr(2)))
r.Cells.Font.Color = RGB(CInt(arr(0)), CInt(arr(1)), CInt(arr(2)))
r.Cells.Font.Name = "Arial" '指定字体为Arial
Next
Application.ScreenUpdating = True '打开屏幕刷新
End Sub
```
这样就可以避免与其他文档中使用的字体冲突了。