【发布时间】:2020-06-30 03:24:28
【问题描述】:
好的,所以我有一个难题。这是我正在尝试的冗长版本:
- 在我已经在 Outlook 中制作的模板中,将其打开并拖入一些文件 - 其中一个是 Excel 文件。
- 打开 Excel 文件并读取到预定的最后一个单元格
- 将最后一行/列的单元格复制到第一个单元格
A1。 - 将之前在步骤 3 中复制的单元格粘贴到 Outlook 正文中
4 号目前是我的问题所在。附上代码
Const xlUp = -4162
'Needed to use the .End() method
Sub Sample()
Dim NewMail As MailItem, oInspector As Inspector
Set oInspector = Application.ActiveInspector
Dim eAttachment As Object, xlsAttachment As Object, i As Integer, lRow As Integer, lPriorRow As Integer, lCommentRow As Integer
'~~> Get the current open item
Set NewMail = oInspector.CurrentItem
'Code given to me from a previous question
Set eAttachment = CreateObject("Excel.Application")
With NewMail.Attachments
For i = 1 To .Count
If InStr(.Item(i).FileName, ".xls") > 0 Then
'Save the email attachment so we can open it
sFileName = "C:/temp/" & .Item(i).FileName
.Item(i).SaveAsFile sFileName
eAttachment.Workbooks.Open sFileName
With eAttachment.Workbooks(.Item(i).FileName).Sheets(1)
lCommentRow = .Cells.Find("Comments").Row
lPriorRow = .Cells.Find("Prior Inspections").Row
lRow = eAttachment.Max(lCommentRow, lPriorRow)
' Weirdly enough, Outlook doesn't seem to have a Max function, so I used the Excel one.
.Range("A1:N" & lRow).Select
.Range("A1:N" & lRow).Copy
'Here is where I get lost; nothing I try seems to work
NewMail.Display
End With
eAttachment.Workbooks(.Item(i).FileName).Close
Exit For
End If
Next
End With
End Sub
我在另一个问题上看到了一个将 Range 对象更改为 HTML 的函数,但它在这里不起作用,因为 此宏代码在 Outlook 中,而不是 Excel 中。
任何帮助将不胜感激。
【问题讨论】: