使用宏在Outlook邮件中读取表格 [英] Read a table in outlook mail using macro
问题描述
我正在编写一个宏以阅读以下电子邮件:
I'm writing a macro to read the below Email:
开始日期:2016年7月7日
Start Date: July-07-2016
Name Accept Approved
John Yes No
Peter No No
我会搜索开始日期"一词,并获得下一个13个字符以将其复制并粘贴到文本文件中.但是我的问题是下一部分是表格式的.因此,当我搜索名称"John"并尝试复制接下来的10个字符时.这是行不通的.
I'm good with search the word "Start date" and get the next 13 character to copy and paste that in a text file. But my problem is the next part is in a Table format. So when I'm searching for the name "John" and trying to copy the next 10 Characters. It doesn't work.
有没有一种方法可以搜索单词"Accept"并获取第一行数据(将为否),然后获取第二行数据(将为否)?有可能吗?
Is there a way to search for the word "Accept" and get the First Row data(Which will be No) and then Second Row data(Which will be No)? Is that possible?
此电子邮件的表格将只有2行.因此,我不需要任何动态方式来获取数据.有人可以引导我吗?
This EMail's table will have only 2 Rows. So, I don't need any dynamic way to get the data. Can someone guide me?
我尝试过先搜索互联网,但是解决方案对于我来说太庞大了.有什么简单的方法吗?我什至尝试了以下解决方案:如何读取使用vba粘贴到Outlook邮件正文中的表?,但是当正文具有ONLY TABLE时,该方法有效.但是我的电子邮件既有文字又有表格.
I've tried searching the internet first, but the solutions are too huge for me to understand. Is there any simple way? I have even tried the solution give here: How to read table pasted in outlook message body using vba? but that method works when the body has ONLY TABLE. But my EMail will have text as well as table.
推荐答案
您实际上可以使用Word对象模型从表中解析出文本-假定电子邮件为HTML格式.
You can actually use the Word Object Model to parse out the text from the table - assuming that the email is in HTML format.
从Inspector.WordEditor属性中获取Word.Document对象,并使用Word对象和方法来获取文本,如以下
Get a Word.Document object from the Inspector.WordEditor property and use Word objects and methods to get the text, like the following below example from MSDN. Just replace ActiveDocument with the variable you declare and set from WordEditor.
Sub ReturnCellContentsToArray()
Dim intCells As Integer
Dim celTable As Cell
Dim strCells() As String
Dim intCount As Integer
Dim rngText As Range
If ActiveDocument.Tables.Count >= 1 Then
With ActiveDocument.Tables(1).Range
intCells = .Cells.Count
ReDim strCells(intCells)
intCount = 1
For Each celTable In .Cells
Set rngText = celTable.Range
rngText.MoveEnd Unit:=wdCharacter, Count:=-1
strCells(intCount) = rngText
intCount = intCount + 1
Next celTable
End With
End If
End Sub
这篇关于使用宏在Outlook邮件中读取表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!