简体   繁体   中英

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

I have designed an Outlook email form that holds several custom fields. One is "reference number", a free text box with the name "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)...

    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". Once I get that right, I can then copy the value into the Excel sheet.

Many thanks for your time.

Shane (Wetherby, UK).

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). 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:

在此处输入图片说明

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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