简体   繁体   English

从 Outlook 电子邮件自定义字段中提取值,并填充 Excel

[英]Extract value from Outlook email message custom field, and populate Excel

I have designed an Outlook email form that holds several custom fields.我设计了一个 Outlook 电子邮件表单,其中包含多个自定义字段。 One is "reference number", a free text box with the name "TextBox1":一个是“参考编号”,一个名为“TextBox1”的自由文本框:在此处输入图片说明

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)...我正在尝试显示该文本框的内容,以便以后可以填充 Excel,使用它作为第一步只是为了显示内容(不起作用)...

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

Can anyone correct this line for me please?任何人都可以帮我纠正这条线吗? I want the message box to display "1234567".我希望消息框显示“1234567”。 Once I get that right, I can then copy the value into the Excel sheet.一旦我做对了,我就可以将该值复制到 Excel 工作表中。

Many thanks for your time.非常感谢您的时间。

Shane (Wetherby, UK). Shane(英国韦瑟比)。

EDIT: 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 EDIT: Here is a screen grab of the object's advanced properties:第二次编辑:这是对象高级属性的屏幕截图:

在此处输入图片说明

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).它有正确的名称 (TextBox1),甚至具有正确的值 (1234567)。 But somehow I cannot get the code to read the value of 1234567 and display it in the message box.但不知何故,我无法获得读取 1234567 的值并将其显示在消息框中的代码。 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:因为“新研究编号”是用于字段名称的内容:

在此处输入图片说明

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.我认为我的部分问题是我对各种用法(属性名称、字段名称、控件名称)感到困惑,并且 VBA 字段属性框有点不清楚。 Nevertheless - thank you to all who contributed;尽管如此 - 感谢所有做出贡献的人; I hope this helps others!我希望这可以帮助其他人! 8) 8)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM