我在"I“栏中有一个附件列表,其中有一个条目”MW“。
文件夹中还有其他具有名称的文件
我想接"JUN2019_fund_MW“
我尝试了下面的代码并得到了一个错误。
.Attachments.Add Pth & Dir(Pth & "*" & Replace(ws.Range("I" & i + 1).Value, "Portfolio Holdings Distribution - Fund ", "") & "*")发布于 2019-08-05 09:35:19
尝尝这个
.Attachments.Add Pth & _
"JUN2019_fund_" & _
Replace(ws.Range("I" & i + 1).Value, "Portfolio Holdings Distribution - Fund ", "") & _
".xls"一个更好的处理方法是
Dim Atthfile As String
Atthfile = pth & _
"JUN2019_fund_" & _
Replace(ws.Range("I" & i + 1).Value, "Portfolio Holdings Distribution - Fund ", "") & _
".xls"
'~~> If file is found, attach else continue without attaching
If Dir(Atthfile) <> "" Then .Attachments.Add Atthfilehttps://stackoverflow.com/questions/57355424
复制相似问题