我已阅读各种其他帖子和尝试修复(重写Word创建脚本以重新安装Office)无济于事 .

当前解决方案:我使用Excel VBA和Microsoft Word文档自动生成电子邮件作为电子邮件的基础 . 我有3个表从我的Excel文件链接到Word文件 . 用于生成电子邮件的VBA在与链接表所在的文件相同的文件中完成 .

使用Microsoft Word的原因是最终用户易于使用,如果他们希望修改电子邮件的某些格式,因为它们不是代码识别的,并且它允许用于电子邮件生成的HTML格式的易用性 .

码:

Option Explicit

Sub doEmail()

Dim sTo As String
Dim sCC As String
Dim sBCC As String
Dim sSub As String
Dim sBody As String
Dim strCC As String
Dim OutApp As Object
Dim OutMail As Object
Dim OutMailEditor As Object
Dim WordApp As Object
Dim WordDoc As Object
Dim varPress As Variant
Dim Today As Date
Dim TodayYear As Integer
Dim wdFile As String
Dim strMess As String
Dim strStyle As String
Dim strTitle As String

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

'Close all Word files currently open
CloseWordDocuments

'Declare variables
wdFile = Some file name
Today = Date
TodayYear = Year(Date)

'MsgBox to confirm sending of email
strMess = "You are about to generate the bi-weekly email." & vbCrLf & vbCrLf
strMess = strMess & "Do you wish to continue?"

strStyle = vbYesNo
strTitle = "PAY ATTENTION"
varPress = MsgBox(strMess, strStyle, strTitle)

If varPress = vbYes Then
        'Set the To and CC address bars
        sTo = Worksheets("Email").Range("R3").Value
        sCC = Worksheets("Email").Range("R4").Value
        'Set the subject
        sSub = "WK" & ISOweeknum(Today)

'Bind Word Application
        On Error Resume Next
    Set WordApp = GetObject(class:="Word.Application")
    On Error GoTo 0

    If WordApp Is Nothing Then
        Set WordApp = CreateObject(class:="Word.Application")
    End If

'Bind Outlook Application
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    Set OutMailEditor = OutMail.GetInspector.WordEditor

'Open Word Doc and copy into email Body
    Set WordDoc = WordApp.documents.Open(Filename:=wdFile)
    WordDoc.Content.Copy
    OutMailEditor.Range.Paste

'Compose the email
    With OutMail
        .To = sTo
        .CC = sCC
        .BCC = sBCC
        .Subject = sSub
        .display          ' This will display the email, but not send it
        '.Send            ' This will send the email
    End With

'Close all instances and free memory
WordApp.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
CloseWordDocuments
    Set OutMail = Nothing
    Set OutApp = Nothing
    Set WordApp = Nothing

End If

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

End Sub

这似乎有时会起作用,但基于测试,它标记了'microsoft excel等待另一个应用程序完成一个ole动作'错误的命中率约为40% .

这对本地计算机上的两个文件都没有问题,我将Word Doc移动到共享驱动器,它仍然没有问题 . 将Excel和Word Doc移动到共享驱动器后,我遇到了问题 .

据我所知,导致错误的挂断似乎是Word访问表的速度有多快,但通过事件查看器查看它并没有给出任何细节 . 仅供参考,Excel文件刚刚超过11MB .

问题:1)是否有解决方案来解决此错误的原因或降低频率? 2)如果Q1的答案为否,是否有另一种方式可以生成电子邮件,允许最终用户在需要时以友好的方式编辑格式?