通过 Outlook 发送时,SharePoint 中的 Word 文件已损坏

问题描述 投票:0回答:1

我有一个宏,可以使用 Excel 工作表中的字段填充 Word 模板,并将其另存为独立文档。

文件保存在 SharePoint 上。我可以打开、下载和编辑它。

Sub inpWord()
    Dim bStarted As Boolean, wdApp As Word.Application, wdDoc As Word.Document, wdTemp As String
    
    wdTemp = "XXXXXX SHAREPOINT LINK XXXXXXX"
    Set inpBook = xlApp.Workbooks("Input Tool")
    
    On Error Resume Next 
        'Open word 
       
    Set wdDoc = Documents.Add(Template:=wdTemp, NewTemplate:=False, DocumentType:=wdNewBlankDocument, Visible:=True)
    Filename = "SHAREPOINT FOLDER LINK" & CStr(RefNum) & ".docx?web=1"
    
    With wdDoc
        Set CCDate = .SelectContentControlsByTitle(1)
        'For loop to populate word template
        .SaveAs Filename
    End With

End Sub

我使用另一个宏从 SharePoint 调用文档后发送该文档。过程中没有错误,但电子邮件中的附件已损坏。

Private Sub CommandButton1_Click()
Dim bStarted As Boolean, oOutlookApp As Outlook.Application, oItem As Outlook.MailItem, xlApp As Object, xlBook As Object

Set xlApp = GetObject(, "Excel.Application")
Set xlBook = xlApp.Workbooks("Purchasing Tracker")

POAttach = "SHAREPOINT LINK" & CStr(PONum) & ".docx?web=1"

On Error Resume Next 'Open Outlook unless already open
    Set oOutlookApp = GetObject(, "Outlook.Application")
    If Err <> 0 Then
        Set oOutlookApp = CreateObject("Outlook.Application")
        bStarted = True
        Err.Clear
    End If
    oOutlookApp.Visible = True

Set oItem = oOutlookApp.CreateItem(olMailItem)

    With oItem
        .To = "RECIEVER"
        .Subject = "XX"
        .HTMLBody = "XX"
        .Attachments.Add Source:=POAttach, Type:=1, _
        DisplayName:="Formula Student Purchase Order: " & CStr(UserForm1.TextBox1.Value)
        .Send
    End With
End Sub

我尝试只包含必要的部分。所有宏都写在 Excel 文档中,Outlook 或 Word 中没有任何宏。

vba sharepoint outlook ms-word email-attachments
1个回答
1
投票

Attachments.Add方法不知道超链接,并且无法处理存储在远程服务器上的文件。您需要将文件下载到本地,然后传递本地文件路径。

附件的来源可以是文件(由带文件名的完整文件系统路径表示)或构成附件的 Outlook 项目。

© www.soinside.com 2019 - 2024. All rights reserved.