首页 > 解决方案 > VBA 文件目录链接到 Outlook

问题描述


我编写了以下代码(基于 SO 中的其他帖子)以将超链接插入到工作簿保存在网络驱动器上的文件夹到电子邮件正文中,并且链接不会显示在正文中电子邮件,我不知道为什么。任何帮助是极大的赞赏。

我确实在参考中检查了 Microsoft Outlook 对象库。

我已经尝试过hyperlink = "<a href=""" & currDir & """></a>"hyperlink = "<a href=" & currDir & "></a>"但无济于事。

以下是完整代码:

Private Sub FileToApprRev_Click()
    Dim OutlookApp As Object, MItem As Object
    Dim Subj As String, EmailAddr As String, Recipient As String
    Dim LienPos As Range, clsDate As Range, address As String, lNum As Range, Street As Range, City As Range, State As Range, ZipCode As Range, CustName As Range
    Dim strBody As String, Email As String, hyperlink As String, currDir As String


    Set wb = Application.ThisWorkbook
    Set wsSI = wb.Sheets("SavedInfo")
    Set Street = wsSI.Range("Street")
    Set City = wsSI.Range("City")
    Set State = wsSI.Range("State")
    Set ZipCode = wsSI.Range("Zip")
    Set lNum = wsSI.Range("Loan_Number")
    Set clsDate = wsSI.Range("Closing_Date")
    Set LienPos = wsSI.Range("Lien_Position")
    Set CustName = wsSI.Range("PBName")

    address = Street & ", " & City & ", " & State & " " & ZipCode

    Set OutlookApp = CreateObject("Outlook.Application")
    Set MItem = OutlookApp.CreateItem(0)

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Email = "SpongeBob@UnderTheSeaHeaven.com"
    currDir = wb.path
    hyperlink = "<a href=""" & currDir & """></a>"
    Debug.Print hyperlink

    strBody = "<p>" & "Hello , " & "<br><br>" & vbNewLine & vbNewLine & _
        "Please complete the Appraisal Review for the file below." & "</p>" & vbNewLine & _
        hyperlink


    With MItem
        .Display
        .to = Email
        .Subject = "ATTN - Appraisal Review" & " - " & CustName & " - " & clsDate
        .HTMLBody = strBody & "<br>" & .HTMLBody
        .send
    End With

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
End Sub

标签: excelvba

解决方案


我想到了。我为文件目录使用了不正确的结构。

target = "\\fsps02\users\......"


推荐阅读