我需要弄清楚如何在MS Access vba中放置代码以附加所选文件夹中的所有文件。 现在我只能从一个特定的位置做一个:
PathLocation = "C:\Test\test.PDF"
If Not IsNull(PathLocation) Then
txtAttach = PathLocation
Set objAttachment = objMailDocument.CREATERICHTEXTITEM("strFileAttachment")
Set objEmbedObject = objAttachment.EMBEDOBJECT(1454, "", txtAttach, "strFileAttachment")
End If
但我真正想要的是收集Test文件夹中的所有内容。
答案 0 :(得分:2)
您需要Dir-语句来运行目录中的所有文件:
Dim PathLocation As String
Dim fileName As String
Dim filePath as String
PathLocation = "C:\Test\"
If Not IsNull(PathLocation) Then
Set objAttachment = objMailDocument.CREATERICHTEXTITEM("strFileAttachment")
fileName = Dir$(PathLocation & "*.*", 0)
Do While fileName <> ""
filePath = PathLocation & fileName
Set objEmbedObject = objAttachment.EMBEDOBJECT(1454, "", filePath, "")
fileName = Dir$()
Loop
End If
通过例如只需PDF格式替换上面代码中的*.*
*.pdf
答案 1 :(得分:0)