从Outlook电子邮件自定义字段中提取值,并填充Excel [英] Extract value from Outlook email message custom field, and populate Excel

查看:295
本文介绍了从Outlook电子邮件自定义字段中提取值,并填充Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个Outlook电子邮件表单,其中包含几个自定义字段.一个是参考号",这是一个名为"TextBox1"的自由文本框:

I have designed an Outlook email form that holds several custom fields. One is "reference number", a free text box with the name "TextBox1":

我试图显示该文本框的内容,以便以后可以填充Excel,并将其用作第一步以仅显示内容(不起作用)...

I am trying to display the contents of that text box so I can later populate Excel, using this as a first step just to display the contents (doesn't work)...

    MsgBox (msg.UserProperties.Find("TextBox1", Outlook.OlUserPropertyType.olText).Value)

任何人都可以为我更正此行吗?我希望消息框显示"1234567". 一旦正确,就可以将值复制到Excel工作表中.

Can anyone correct this line for me please? I want the message box to display "1234567". Once I get that right, I can then copy the value into the Excel sheet.

非常感谢您的宝贵时间.

Many thanks for your time.

Shane (英国威瑟比).

Shane (Wetherby, UK).

这是显示对象的声明和分配的更完整的代码:

Here is more complete code showing the declaration and assignment of objects:

Dim rng As Excel.Range
Dim msg As Outlook.MailItem
Dim nmspace As Outlook.NameSpace
Dim folder As Outlook.MAPIFolder
Dim item As Object

Set nmspace = Application.GetNamespace("MAPI")
Set folder = nmspace.PickFolder

'Look at each email message in a folder
For Each item In folder.Items
    intColumnCounter = 1
    Set msg = item
    intRowCounter = intRowCounter + 1
    Set rng = wks.Cells(intRowCounter, intColumnCounter)
    rng.Value = msg.To

...这里有更多项目可以提取发件人地址,主题,发送日期等)...

...more items here to pick up sender address, subject, date sent, etc)...

    MsgBox (msg.UserProperties.Find("TextBox1", Outlook.OlUserPropertyType.olText).Value)
    'This is the field whose value I want to take for Excel
Next item

第二 这是该对象的高级属性的屏幕截图:

SECOND Here is a screen grab of the object's advanced properties:

这是在电子邮件模板中输入的正常"自由文本框.它具有正确的名称(TextBox1),甚至具有正确的值(1234567).但是以某种方式,我无法获取代码以读取1234567的值并将其显示在消息框中. 我很困惑它需要比我聪明的人!谢谢所有正在考虑这一点的人.

It is a "normal" free text box entered into an email template. It's got the right name (TextBox1), and even has the right value (1234567). But somehow I cannot get the code to read the value of 1234567 and display it in the message box. I'm stumped. it needs someone clever than me! Thank you to all who are pondering this one.

推荐答案

已解决!(道歉). 较早的答复使我开始思考.我改用此行:

SOLVED!!! (Apologies for shouting). Earlier replies got me thinking. I tried this line instead:

MsgBox (msg.UserProperties.Find("New - Study Number").Value)

字段名称使用的是新研究编号":

as "New-Study Number" is what was used for the field name:

我认为我的问题的部分原因是我对各种用法(属性名称,字段名称,控件名称)感到困惑,而VBA字段属性框还不清楚. 尽管如此-感谢所有贡献者;希望这对其他人有帮助! 8)

I think part of my problem was I was getting confused with the various usages (property name, field name, control name) and the VBA field properties boxes being a little unclear. Nevertheless - thank you to all who contributed; I hope this helps others! 8)

这篇关于从Outlook电子邮件自定义字段中提取值,并填充Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆