Estoy usando este código:
Public Sub GetSelectedItem_Click()
' This uses an existing instance if available (default Outlook behavior).
Dim oApp As New Outlook.Application
Dim oExp As Outlook.Explorer
Dim oSel As Outlook.Selection ' You need a selection object for getting the selection.
Dim oItem As Object ' You don't know the type yet.
Set oExp = oApp.ActiveExplorer ' Get the ActiveExplorer.
Set oSel = oExp.Selection ' Get the selection.
For i = 1 To oSel.Count ' Loop through all the currently .selected items
Set oItem = oSel.Item(i) ' Get a selected item.
DisplayInfo oItem ' Display information about it.
Next i
End Sub
Sub DisplayInfo(oItem As Object)
Dim strMessageClass As String
Dim oAppointItem As Outlook.AppointmentItem
Dim oContactItem As Outlook.ContactItem
Dim oMailItem As Outlook.MailItem
Dim oJournalItem As Outlook.JournalItem
Dim oNoteItem As Outlook.NoteItem
Dim oTaskItem As Outlook.TaskItem
Dim oBody As String
Dim uniqueKeyStart As String
Dim uniqueKeyEnd As String
Dim UniqueKey As Integer
' You need the message class to determine the type.
strMessageClass = oItem.MessageClass
If (strMessageClass = "IPM.Appointment") Then ' Calendar Entry.
Set oAppointItem = oItem
MsgBox oAppointItem.Subject
MsgBox oAppointItem.Start
ElseIf (strMessageClass = "IPM.Contact") Then ' Contact Entry.
Set oContactItem = oItem
MsgBox oContactItem.FullName
MsgBox oContactItem.Email1Address
ElseIf (strMessageClass = "IPM.Note") Then ' Mail Entry.
Set oMailItem = oItem
MsgBox oMailItem.Subject
oBody = oMailItem.Body
uniqueKeyStart = InStr(1, oBody, "::")
uniqueKeyEnd = InStrRev(oBody, "::")
Dim MPLCuser As String
MPLCuser = Environ("UserName")
UniqueKey = Mid(oBody, uniqueKeyStart + 2, uniqueKeyEnd - uniqueKeyStart - 2)
Call ConfirmClaim(UniqueKey, MPLCuser)
MsgBox UniqueKey
ElseIf (strMessageClass = "IPM.Activity") Then ' Journal Entry.
Set oJournalItem = oItem
MsgBox oJournalItem.Subject
MsgBox oJournalItem.Actions
ElseIf (strMessageClass = "IPM.StickyNote") Then ' Notes Entry.
Set oNoteItem = oItem
MsgBox oNoteItem.Subject
MsgBox oNoteItem.Body
ElseIf (strMessageClass = "IPM.Task") Then ' Tasks Entry.
Set oTaskItem = oItem
MsgBox oTaskItem.DueDate
MsgBox oTaskItem.PercentComplete
End If
End Sub
Function ConfirmClaim(myUniqueKey As Integer, MPLCuser As String)
Dim UserNoSpaces
If VarType(myUniqueKey) = 2 Then ' Must be a Number
UserNoSpaces = Replace(MPLCuser, " ", "")
MyApp = "C:\Program Files\Internet Explorer\IEXPLORE.EXE"
MyURL = url & myUniqueKey & "&claimuser=" & UserNoSpaces
MsgBox (MyURL)
Shell (MyApp & " " & MyURL), vbHide
Else
MsgBox "You have not specified a correct claim"
End If
End Function
Con ese código primero vemos qué se ha seleccionado, luego en base a eso hacemos una cosa u otra. Lo que nos interesa es cuando seleccionamos un mail que lo que hacemos es buscar un valor concreto que trae el mail que está entre "::" y lo rescatamos, ese valor lo mandamos a una página que con el valor y el usuario debe generarnos un sumario que luego vamos a hacer Ctrl+P a una impresora PDF y como nombre tendrá:
$PDFname = $UniqueKey."-".$MPLCuser."-".date(d/m/Y H:i).".pdf"
$PDFfolder = "X:/PDFWeb/" // Esto será una unidad mapeada.
Lo que quiero hacer a continuación es lo que estoy preguntando en mi otra pregunta. Que aunque está relacionada con esta como no son cosas iguales no la he puesto aquí.