我需要设置路径,让它可以在任何桌面打开。
这是我目前的代码:
Dim myOlApp As Outlook.Application
Dim myitem As Outlook.MailItem
Dim n As Integer
Set myOlApp = CreateObject("Outlook.Application")
Set myitem = myOlApp.CreateItemFromTemplate("C:\Users\User\documents\Template.msg")
With myitem
For n = 0 To Me.EmailList.ListCount - 1
.Attachments.Add (Me.EmailList.ItemData(n))
Next n
myitem.Subject = Nz("")
myitem.To = Nz(Me.txtCustomerEmailAddress1)
myitem.Display
最佳答案
由于您将问题标记为 access-vba,我假设您是从 ms access 中发送电子邮件。我还假设您指的是 Template.msg 的路径。如果是这样,您可以将 Template.msg 存储到 MS Access 中的表中(作为二进制数据),然后在发送电子邮件之前将其保存到磁盘。您的代码类似于:
Set myOlApp = CreateObject("Outlook.Application")
...
dim filesPath as String
filesPath = Environ$("USERPROFILE") ' this will return the current user's folder
Call writeTemplate(filesPath) ' this will write Template.msg from table to a file in filesPath path
Set myitem = myOlApp.CreateItemFromTemplate(filesPath & "\Template.msg")
在“writeTemplate()”方法中,您只需将 Template.msg 保存到磁盘,在目录 filesPath 中。
关于ms-access - 打开任何桌面VBA Access的文件路径,我需要设置路径以便它可以在任何桌面上打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32411303/