excel - 尝试使用 Range.Replace 查找和替换 qoute 符号时出错
问题描述
我有一个宏文件,它可以拆分文件并按特定列表命名它们未创建此列表中包含引号的文件的名称,"
我只想用该范围内的常规空间查找和替换所有文件。
但是当我运行宏时它会返回我
参数不是可选的。
有人能找到我的问题在哪里吗?
'Loop for creating files
For i = 2 To FilesCounter
NewWBName = EmailWS.Cells(i, 1).Value
Set NewWB = Workbooks.Add
With SplitWS
.Range(.Cells(1, 1), .Cells(LastRow, LastColumn)).AutoFilter Field:=1, Criteria1:=NewWBName
.Range(.Cells(1, 2), .Cells(LastRow, LastColumn)).SpecialCells(xlCellTypeVisible).Copy 'Copy cells starting from column B
End With
With NewWB.Worksheets(1)
.Cells(1, 1).PasteSpecial xlPasteFormats
.Cells(1, 1).PasteSpecial xlPasteValues
.Cells.EntireColumn.AutoFit
End With
'find and replace all th " in the WB names list
With EmailWS
.Range("$A:$A").Replace What:=""", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False"
.Cells(i, 1).Value = NameForFile & "" & NewWBName
End With
NewWB.SaveAs fileName:=DesPath & "\" & NameForFile & "" & NewWBName & ".xlsx", Password:=PassFile
NewWB.Close
Next i
解决方案
"
在 VBA 中可以写成""""
或Chr(34)
"""
不一样""""
在即时窗口中输入这个
?Chr(34)
" '<~~ This is what you will get
然后这个
?"""" = Chr(34)
True '<~~ This is what you will get
现在试试
?""" = Chr(34)
看看你得到了什么:)
在您的代码中,用"""
or""""
替换Chr(34)
它变成What:=""""
推荐阅读
- vba - 有没有办法用 VBA 以只读方式打开具有写入密码的 PowerPoint 文件,与使用 Word 文档的方式相同?
- mongodb - 通过 PrestoDB 从 MongoDB ObjectId 获取时间戳
- bash - MacOS bash 脚本不支持双引号
- python - 是否可以在python中逐部分分解error.path消息?
- javascript - 我想将对象推送到 Vue.js 中的对象数组中
- java - Spring 以合格 bean 为条件
- php - 如何修复脚本缓存:清除 symfony 4 中返回的错误代码 255
- excel - 从 OneDrive 同步的 Excel 文件显示在线文件路径,而不是本地文件
- c++ - delete[] 在 C++ 中用 new 分配的特定数组块
- wordpress - pre_get_posts 不限制每页的帖子