更新
马特,在您更新的帖子中,将代码更改为:
Function CleanName(strName As String) As String
'will clean part # name so it can be made into valid folder name
'may need to add more lines to get rid of other characters
CleanName = Replace(strName, "/", "") '-> only use strName the first time, since you are passing that string to the Function
CleanName = Replace(CleanName, "*", "")
CleanName = Replace(CleanName, ".", "")
CleanName = Replace(CleanName, "\", "") '-> if you use strName here, you lose your first 3 replacments
CleanName = Replace(CleanName, """", "") '-> this is the correct syntax to remove the "
'-> to Sid's point, this should work too
'CleanName = Replace(CleanName, Chr(34), "")
End Function
既然别人都在回答,那我就把评论改成回答入党了!
尝试
CleanName = Replace(CleanName, """", "")
您需要将引号括在双引号中,以告诉 VBA 您要查找实际的实际引号,而不是它自动识别的特殊字符。 (丹尼尔库克下面的评论也涉及到它。)
为了他人的利益,CleanName 是一个自定义函数,用于清除不需要的字符串。有关更多信息,请参阅此链接:CleanName