【发布时间】:2022-06-20 20:37:26
【问题描述】:
这是我的代码:
Function GetAttachmentById(Id As String) As Attachment
Dim newAttachment As Attachment
Set newAttachment = New Attachment
Dim Directory As String
Directory = "C:\Users\user\Desktop\VBA"
Dim fso, newFile, folder, Files
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(Directory)
Set Files = folder.Files
For Each file In Files
If InStr(file.Name, Id) > 0 Then
newAttachment.Id = Id
newAttachment.AttachmentName = file.Name
newAttachment.AttachmentPath = file.Path
End If
Next file
GetAttachmentById = newAttachment
在我尝试返回附件对象的最后一行出现错误:
对象变量或未设置块变量
正如我在调试器中看到的,newAttachment 创建得很好,而且我没有“with”块,所以我不确定下一步该去哪里。
【问题讨论】: