【问题标题】:Open file path for any desktop VBA Access, I need to set the path so that it can be opened on any desk top任何桌面 VBA Access 的打开文件路径,我需要设置路径,以便它可以在任何桌面上打开
【发布时间】:2015-09-05 09:05:25
【问题描述】:

我需要设置路径,以便可以在任何桌面上打开。

这是我目前的代码:

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

【问题讨论】:

  • 在任何桌面世界/公司/网络范围内打开?
  • 公司或网络会有所帮助,谢谢

标签: ms-access vba


【解决方案1】:

由于您将问题标记为 access-vba,我假设您是从 ms 访问中发送电子邮件。我还假设您指的是 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 中。

【讨论】:

  • 感谢 chrisl08。我已将 Dim sUsername 作为字符串声明,但是我在下面的行中得到“编译错误”子或未定义的函数。调用 writeTemplate(filesPath)。是的,你是对的,我在访问表单上有一个按钮,可以在文档文件夹中选择模板。
  • 哪一行你得到“Sub or function not difined”?
  • @Neilster 如果您指的是 writeTemplate() 方法,我将其留给您实现:-)。这是一个例子:support.microsoft.com/en-us/kb/103257
  • 谢谢 chrisl08 我想我已经整理好了。感谢你的帮助。 (-:
  • 总是乐于提供帮助。你会考虑将我的答案标记为正确吗?谢谢:-)
【解决方案2】:

在执行此类操作时,我强烈建议您使用 VBA 的 environ() 函数,该函数将根据用户和/或机器返回上下文路径。您可以在调试窗口中尝试以下操作:

environ("username")
environ("userdomain")

可以通过environ()检索所有环境变量

关于 environ() 的一些有趣代码可以在 herethere 找到

【讨论】:

    猜你喜欢
    • 2010-09-05
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    相关资源
    最近更新 更多