Argh,Object不支持此属性或方法错误438!
我没有试过这个,但我认为它可能有用:
objFS.System.IO.Path.GetFileName(fileName)
if objFS.System.IO.Path.GetFileName(fileName) = "VS12_WID1" Then
fileName = AFile.Name
getFileName = filePath & "/" & fileName
我应该简单一点,然后尝试重命名该文件。
Sub AddAttachment()
Dim myAttachments As Outlook.Attachments
Dim getFile, fileName, filePath As String
Set filePath = "F:\"
Set fileName = "V_W_*_*_.pdf"
Set getFile = "filePath" & "fileName"
Set MyApp = CreateObject("Outlook.Application")
Set myItem = MyApp.CreateItem(0)
Set myAttachments = myItem.Attachments
With myItem
.To = "email@mail.com"
.CC = ""
.Subject = "test"
myAttachments.Add getFile
.ReadReceiptRequested = False
.HTMLBody = "Report(s) Attached"
End With
myItem.Send
End Sub
我收到编译错误:对象需要突出显示Sub AddAttachment()和Set filePath。我觉得这个工作非常接近!
更新代码:
Sub AddAttachment()
Dim myAttachments As Outlook.Attachments
Dim getFileName, fileName, filePath As String
Dim objFS: Set objFS = CreateObject("Scripting.FileSystemObject")
Set filePath = "F:\"
Set getFileName = filePath & fileName
Set MyApp = CreateObject("Outlook.Application")
Set myItem = MyApp.CreateItem(0)
Set myAttachments = myItem.Attachments
For Each fileName In filePath
If fcase(objFS.GetExtensionName(fileName)) = "VS111111_WID111A" Then
fileName = "VS111111_WID111A.pdf"
Exit For
End If
Next
With myItem
.To = "email@mail.com"
.CC = ""
.Subject = ""
myAttachments.Add getFileName
.ReadReceiptRequested = False
.HTMLBody = "Report(s) Attached"
End With
myItem.Send
End Sub
我有足够的知识来阅读脚本以了解正在发生的事情。我制作的代码只能找到固定的文件名。如何使文件名动态化?
Sub AddAttachment()
Dim myAttachments As Outlook.Attachments
Set MyApp = CreateObject("Outlook.Application")
Set myItem = MyApp.CreateItem(0)
Set myAttachments = myItem.Attachments
With myItem
.To = "email@address.com"
.CC = "email@address.com"
.Subject = ""
myAttachments.Add "F:\constantFilenameHas8char_constantFilenameHas7char_variableHas5Int_todaysModifiedDate_variableHas6Int.pdf"
.ReadReceiptRequested = False
.HTMLBody = "Report(s) Attached"
End With
myItem.Send
End Sub
答案 0 :(得分:0)
您的查询不清楚如何获取文件名。请尝试使用 变量并根据需要传递文件路径和名称。
dim FileToAttach as string
FileToAttach =“FilePath”& “文件名”
myAttachments.Add FileToAttach
为了您的更新代码
Sub AddAttachment()
将我的附件作为Outlook.Attachments
Dim getFileName,filename
Dim filePath As Object
Dim objFS As FileSystemObject
设置objFS = New FileSystemObject
设置filePath = objFS.GetFolder(“C:\ Users \ Dinesh \ Desktop \”)
设置MyApp = CreateObject(“Outlook.Application”)
设置myItem = MyApp.CreateItem(0)
设置myAttachments = myItem.Attachments
对于每个AFile In filePath.Files
Debug.Print UCase(objFS.GetExtensionName(fileName))
如果UCase(objFS.GetExtensionName(AFile))=“PDF”那么
fileName = AFile.Name
getFileName = filePath& “/”&文件名
退出
结束如果
下一页
用myItem
.To =“”
.CC =“”
.Subject =“”
myAttachments.Add getFileName
.ReadReceiptRequested = False
.HTMLBody =“报告附件”
。显示
结束
“myItem.Send
结束子