当用户为我的宏设置"另存为"输出名称时,我希望检查特殊字符是否会导致保存文件时出现错误-
我使用RegExp进行如下操作:
我因为符号(
解决方案请查看
[\/:*?<>|]
。我使用RegExp进行如下操作:
Dim regEx As New RegExp
Dim strSpecChar As String: strSpecChar = "*[\/:*?<>|]*" 'Compile Error here
Dim OutputFileName As String: OutputFileName = InputBox("Enter File Name")
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = strSpecChar
End With
If regEx.Test(OutputFileName) Then
'error msg
End If
我因为符号(
|
)导致编译出错,错误信息为“编译错误:无效字符”。我已经尝试用反斜杠转义该符号,但没有解决问题。有人能帮忙吗?我阅读了一些文章,包括这篇,但没能找到解决方法。解决方案请查看
blog.tkacprow.pl
下面的评论和Alex
的答案(他指出了一个打字错误并解释了错误代码5018)。请从以上strSpecChar变量中删除*
。
Instr()
函数完全可以胜任。你最终会得到大约相同数量的代码行,但我会花时间提取一个SafeFileName(filename as string) as string
函数。 - RubberDuck