+ -
当前位置:首页 → 问答吧 → VBA调用模板CreateItemFromTemplate中的文件路径

VBA调用模板CreateItemFromTemplate中的文件路径

时间:2011-05-04

来源:互联网

我每个月都有不少固定格式的邮件要发,用下面的代码可以从excel里面调用指定的模板。
但是CreateItemFromTemplate里面现在只会用绝对路径,有没有办法可以用相对路径或者从excel的单元格内容传入路径?

Sub EmailWithOutlook()
    Dim oApp As Object, oMail As Object
    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.CreateItemFromTemplate("C:\test.oft"")

    With oMail

        .Display
    End With
   
    Set oMail = Nothing
    Set oApp = Nothing
End Sub

作者: rodney   发布时间: 2011-05-04

Sub EmailWithOutlook()
    Dim oApp As Object, oMail As Object
    Set oApp = CreateObject("Outlook.Application")
    Set oMail = oApp.CreateItemFromTemplate(activecell.value & "\test.oft"")

    With oMail

        .Display
    End With
   
    Set oMail = Nothing
    Set oApp = Nothing
End Sub

作者: doitbest   发布时间: 2011-05-04

谢谢回答,不过出错Expected: list seperator or)
我曾经试用ActiveWorkbook.Path也是这个问题。不知何解。

作者: rodney   发布时间: 2011-05-04

如果是新建文件, ActiveWorkbook.Path是空值。

你是打开文件,还是新建文件?文件保存过了吗?

作者: dsd999   发布时间: 2011-05-04

文件保存过了。在编辑器里看也确实拿到了excel文件本身的路径。应该是出在连接符的问题上。

作者: rodney   发布时间: 2011-05-04

Set oMail = oApp.CreateItemFromTemplate(ActiveWorkbook.Path & "\test.oft")

试过没问题。

作者: dsd999   发布时间: 2011-05-04