Sub tem()
Function removeSpecial(sInput As String) As String
Dim sSpecialChars As String
Dim i As Long
sSpecialChars = "\/:*?""<>|"
For i = 1 To Len(sSpecialChars)
sInput = Replace$(sInput, Mid$(sSpecialChars, i, 1), " ")
Next
removeSpecial = sInput
End Function
End Sub
答案 0 :(得分:2)
您不能在Sub中放置函数声明。这里是重新格式化的代码,并且Sub / End Sub行被注释掉了。
'Sub tem()
Function removeSpecial(sInput As String) As String
Dim sSpecialChars As String
Dim i As Long
sSpecialChars = "/:*?""<>|"
For i = 1 To Len(sSpecialChars)
sInput = Replace$(sInput, Mid$(sSpecialChars, i, 1), " ")
Next
removeSpecial = sInput
End Function
'End Sub
当它从即时窗口运行时:
?removespecial("a/a:a*a?a""a<a>a|a")
a a a a a a a a a