【发布时间】:2017-11-23 01:42:25
【问题描述】:
我正在帮助我的朋友使用 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).Paste 是她的错误。我们都从工具中声明了相同的引用,但错误仍然在这一行。为什么它不能在她的机器上运行可能是什么错误?
PS。她不想使用HTMLbody。
【问题讨论】:
-
你为什么有2个
With olEmail? -
我已经用 olEmail 删除了 1 个,但仍然没有解决我们的错误。
-
作为@tlemaster 的stated,将其更改为
wdDoc.Range.Paste会使您的代码在我的最后工作。它还会在复制的 Range 之前粘贴ebody。It didn't give us the outcome that we want。请具体说明您遇到的问题和错误,以便我们为您提供帮助。