Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 无法在其他计算机中运行发送电子邮件的代码_Vba_Excel_Outlook - Fatal编程技术网

Vba 无法在其他计算机中运行发送电子邮件的代码

Vba 无法在其他计算机中运行发送电子邮件的代码,vba,excel,outlook,Vba,Excel,Outlook,我正在帮助我的朋友使用VBA开发代码。我已经成功地在我的笔记本电脑上运行了这些代码,但是当我们将代码复制到她的机器上时,她遇到了错误 这是我的密码: Sub Test() Call sendingEmailWithChecklist("Book1.xlsm") End Sub Sub sendingEmailWithChecklist(workbookName As String) Dim recipient As String Dim cc As String

我正在帮助我的朋友使用VBA开发代码。我已经成功地在我的笔记本电脑上运行了这些代码,但是当我们将代码复制到她的机器上时,她遇到了错误

这是我的密码:

Sub Test()

    Call sendingEmailWithChecklist("Book1.xlsm")

End Sub

Sub sendingEmailWithChecklist(workbookName As String)

    Dim recipient As String
    Dim cc As String
    Dim subject As String
    Dim body As Range
    Dim greetings As String
    Dim message As String
    Dim signature As String
    Dim ebody As String

    Dim olApp As Outlook.Application
    Dim olInsp As Outlook.Inspector
    Dim wdDoc As Word.Document
    Dim olEmail As Outlook.MailItem
    Dim worksheetName As String
    Dim content As Range

    Set olApp = New Outlook.Application
    Set olEmail = olApp.CreateItem(olMailItem)

    Sheet2.Activate

    recipient = Range("B3").Value
    cc = Range("B4").Value
    subject = Range("B5").Value

    greetings = Range("B6").Value
    message = Range("B7").Value

    ebody = greetings & vbNewLine & vbNewLine & message & vbNewLine

    signature = Range("B8").Value

    'Workbooks(workbookName).Activate
    worksheetName = "Sheet1"


    With olEmail
        .Display

        .To = recipient
        .cc = cc
        .subject = subject

        Set olInsp = .GetInspector
        Set wdDoc = olInsp.WordEditor

        Workbooks(workbookName).Worksheets(worksheetName).Activate

        Workbooks(workbookName).Worksheets(worksheetName).Cells.Copy

        'Range("A1:F17").Select
        'Selection.Copy

    End With

    With olEmail

        .Display
        wdDoc.Range(1, 1).Paste
        wdDoc.Range.InsertBefore ebody

        '.Send


    End With

End Sub
wdDoc.Range(1,1).粘贴是她的错误。我们都声明了来自工具的相同引用,但错误仍然在这一行。为什么它不能在她的机器上运行,可能是什么错误

另外,她不想使用
HTMLbody

而不是

wdDoc.Range(1, 1).Paste
试一试


如果要进一步控制在邮件正文中粘贴数据的方式,可能需要使用单词
选择
对象(表达式),而不是
范围
。比如:

wdDoc.Application.Selection.PasteAndFormat wdFormatOriginalFormatting

上面的粘贴复制的项目及其原始格式。
您可以根据预期结果选择其他
粘贴和格式
选项。

为什么olEmail有2个
?我已经用olEmail删除了1个,但仍然没有修复我们的错误。@tlemaster,将其更改为
wdDoc.Range.Paste
将使您的代码在我这端工作。它还会将
ebody
粘贴到复制的范围之前
它没有给我们想要的结果
。请具体说明您遇到的问题和错误,以便我们帮助您。我的电子书中的文本粘贴在我的范围的第一个单元格中。它没有给我们我们想要的结果want@RouellaMayGabineteAmponin什么错误,什么线路?在那条线路上。wdDoc.Application.Selection.PasteAndFormatwdFormatOriginalFormatting@RouellaMayGabineteAmponin错误消息是什么?您确定有正确的参考集吗?
wdDoc.Application.Selection.PasteAndFormat wdFormatOriginalFormatting