Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.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
outlook电子邮件正文未复制到excel_Excel_Vba_Outlook - Fatal编程技术网

outlook电子邮件正文未复制到excel

outlook电子邮件正文未复制到excel,excel,vba,outlook,Excel,Vba,Outlook,下面的代码将从指定的电子邮件打开指定的文件。但是,它不会将正文消息拆分为excel中的不同行,有什么建议吗 For i = LBound(MyAr) To UBound(MyAr) '~~> This will give you the contents of your email '~~> on separate lines Debug.Print MyAr(i) Next i End With Const xlUp As Long=-4162

下面的代码将从指定的电子邮件打开指定的文件。但是,它不会将正文消息拆分为excel中的不同行,有什么建议吗

For i = LBound(MyAr) To UBound(MyAr)
    '~~> This will give you the contents of your email
    '~~> on separate lines
    Debug.Print MyAr(i)
Next i
    End With

Const xlUp As Long=-4162
子ExportToExcel(我的邮件作为邮件项)
Dim strID作为字符串,olNS作为Outlook.NameSpace
以Outlook.MailItem的形式发送邮件
将strFileName设置为字符串
'~~>Excel变量
Dim oXLApp作为对象,oXLwb作为对象,oXLws作为对象
暗淡的光线和长的一样
strID=MyMail.EntryID
Set olNS=Application.GetNamespace(“MAPI”)
设置olMail=olNS.GetItemFromID(strID)
“~~>建立EXCEL应用程序对象
出错时继续下一步
设置oXLApp=GetObject(,“Excel.Application”)
“~~>如果找不到,则创建新实例
如果错误号为0,则
设置oXLApp=CreateObject(“Excel.Application”)
如果结束
呃,明白了
错误转到0
“~~>显示Excel
oXLApp.Visible=True
“~~>打开相关文件
设置oXLwb=oXLApp.Workbooks.Open(“C:\Users\ltorres\Documents\multiplier.xlsx”)
“~~>设置相关的输出表。更改(如适用)
设置oXLws=oXLwb.板材(“板材1”)
lRow=oXLws.Range(“A”&oXLws.Rows.Count)。End(xlUp)。Row+1
“~~>写入outlook
使用oXLws
Dim MyAr()作为字符串
MyAr=拆分(olMail.Body,vbCrLf)
对于i=LBound(MyAr)到UBound(MyAr)
“~~>这将为您提供电子邮件的内容
“~~>在单独的行上
调试.打印MyAr(i)
接下来我
以
“~~>关闭并清理Excel
oXLwb.Close(真)
奥克斯拉普,退出
设置oXLws=Nothing
设置oXLwb=Nothing
设置oXLApp=Nothing
设置olMail=Nothing
设置olNS=Nothing

End Sub

您可以在
With
语句中设置
lRow
,但您还需要在每次有
MyAr
定义的换行符时添加一行,请尝试:

With oXLws
lRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1
Dim MyAr() As String
MyAr = Split(olMail.Body, vbCrLf)
For i = LBound(MyAr) To UBound(MyAr)
    .Range("A" & lRow).Value = MyAr(i)
    lRow = lRow + 1
Next i
End With

lRow=oXLws.Range(“A”&oXLApp.Rows.Count).End(xlUp).Row+1
是否指的是
oXLws
中的行?另外,即时窗口中是否有任何内容出现在Debug.Print MyAr(i)?@jordan正确我已修复,excel中显示的是主题和发件人列A和B,但不是Debug.Print中的正文。它显示的是电子邮件的正文***请注意,我想将邮件正文分为不同的行。谢谢,这会让我找到我想要的方向
With oXLws
lRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1
Dim MyAr() As String
MyAr = Split(olMail.Body, vbCrLf)
For i = LBound(MyAr) To UBound(MyAr)
    .Range("A" & lRow).Value = MyAr(i)
    lRow = lRow + 1
Next i
End With