Excel VBA wordEditor粘贴打破超级链接与下划线(“_”)

时间:2016-12-02 13:16:17

标签: excel vba excel-vba email sharepoint

情景:

我有一个Excel VBA脚本,它结合了文本和图表,将其复制并粘贴到电子邮件中。在电子邮件中,有一个指向共享文档的超链接。

最近我们从KnowledgeLink迁移到Sharepoint,用于我公司的文件存储。这样,此共享文档的URL已更改。现在URL已经改变了,我开始看到URL在Excel中的位置:

https://teamsites.companyname.com/sites/ENT0007/DA/_layouts/15/WopiFrame.aspx?sourcedoc= {905dbdf0-3bdb-405F-957d-81a8c7234f56}&安培;行动=默认

但是在电子邮件中它显示为不起作用:

../../../../../ ENT0007 / DA / _layouts / 15 / DocIdRedir.aspx?ID = UZD3Z4HDMQ6J-1525442641-99

通过反复试验,我相信我已经确定URL中的“_”是问题所在。如果我将其取出并运行宏,它会很好地粘贴到电子邮件中。

问题是,作为Sharepoint的大型企业部署,我无法控制URL。看来,当它转到在sharepoint中查看的文档时,URL会有一个下划线。

以下是我用于电子邮件粘贴的代码:

Sub sendSUEmailDraft()
'Call SavetoSP
Dim mailApp, mail As Object
Dim olMailItem, wEditor As Variant
Dim Rng As range

Set Rng = Nothing
On Error Resume Next
Set Rng = Sheets("SheetName").range("A1:K55").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Rng Is Nothing Then
    MsgBox "The selection is not a range or the sheet is protected" & _
           vbNewLine & "please correct and try again.", vbOKOnly
    Exit Sub
End If

With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With

Set mailApp = CreateObject("Outlook.Application")
Set mail = mailApp.CreateItem(olMailItem)
mail.Display
Set wEditor = mailApp.ActiveInspector.wordEditor
Rng.Copy
With mail
    .To = [draftTo]
    .SentOnBehalfOfName = "email@companyname.com"
    .CC = ""
    .BCC = ""
    .Subject = "E-mail Title")
    .Display   'or use .Display
End With
wEditor.Application.Selection.Paste
End Sub

0 个答案:

没有答案