本帖最后由 413191246se 于 2020-8-1 20:26 编辑
* 在保存或另存为文档时,提示有 9 个不宜包含在文件名中的字符(\/:*?"<>|),应当予以回避;但实际上回车符、制表符也是两个个不宜包含在文件名中的字符。所以,共有 11 个不宜包含在文件名中的字符,都应予以删除,才能保存文档,请参见下面的代码(两个宏是一样的,后面的是优化整合的):
- Sub FileSave_DeleteForbiddenCharacters()
- Dim i$
- i = ActiveDocument.Paragraphs(1).Range.Text
- i = Replace(i, "", "")
- i = Replace(i, "/", "")
- i = Replace(i, ":", "")
- i = Replace(i, "*", "")
- i = Replace(i, "?", "")
- i = Replace(i, """", "")
- i = Replace(i, "<", "")
- i = Replace(i, ">", "")
- i = Replace(i, "|", "")
- i = Replace(i, vbCr, "")
- i = Replace(i, vbTab, "")
- ActiveDocument.SaveAs2 FileName:=i
- ActiveDocument.Close
- End Sub
- Sub FileSave_DeleteForbiddenCharacters_Optimize()
- Dim i$
- i = ActiveDocument.Paragraphs(1).Range.Text
- i = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(i, "", ""), "/", ""), ":", ""), "*", ""), "?", ""), """", ""), "<", ""), ">", ""), "|", ""), vbCr, ""), vbTab, "")
- ActiveDocument.SaveAs2 FileName:=i
- ActiveDocument.Close
- End Sub
复制代码 |