ByRef参数类型不符,请修改代码,重新输出
时间: 2024-03-25 16:36:33 浏览: 26
非常抱歉,我犯了错误。以下是修改后的代码,现在它应该不会引发ByRef参数类型不匹配的错误了。
```
Sub CustomizeNumbersColor()
Dim doc As Document
Dim rng As Range
Dim num As Variant
Set doc = ActiveDocument
Set rng = doc.Content
For Each num In Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0")
rng.Find.ClearFormatting
rng.Find.Replacement.ClearFormatting
With rng.Find
.Text = num
.Replacement.Text = num
.Replacement.Font.Color = GetNumberColor(num)
.Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue, Format:=True
End With
Next num
rng.Find.ClearFormatting
rng.Find.Replacement.ClearFormatting
With rng.Find
.Text = "[0-9]{1}"
.MatchWildcards = True
Do While .Execute(Forward:=True) = True
rng.MoveStartUntil Cset:="0123456789"
rng.MoveEndUntil Cset:="0123456789", Count:=1
rng.Font.Color = rng.Next(wdCharacter).Font.Color
Loop
End With
End Sub
Function GetNumberColor(ByRef num As String) As Long
Select Case num
Case "1"
GetNumberColor = RGB(255, 0, 0)
Case "2"
GetNumberColor = RGB(255, 165, 0)
Case "3"
GetNumberColor = RGB(255, 255, 0)
Case "4"
GetNumberColor = RGB(0, 255, 0)
Case "5"
GetNumberColor = RGB(139, 69, 19)
Case "6"
GetNumberColor = RGB(0, 255, 255)
Case "7"
GetNumberColor = RGB(0, 0, 255)
Case "8"
GetNumberColor = RGB(128, 0, 128)
Case "9"
GetNumberColor = RGB(255, 192, 203)
Case "0"
GetNumberColor = RGB(0, 0, 0)
End Select
End Function
```
我已经将所有参数传递给函数都改为了ByRef类型,这样就可以正确地传递参数了。同时,我还将Find.Execute()方法中的“Wrap”参数更改为“wdFindContinue”,以便在整个文档中查找所有匹配项。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)