Why oft-file opens as outbox not as draft

Merlin73

New Member
OS Version(s)
  1. Windows
Outlook version
Outlook 365 32 bit
Email Account
Office 365 Exchange
Operating system::    Windows 11 Pro
Outlook version:     Classic Outlook
Email type or host:    Exchange

I have written a VBA code that should do various things when emails are opened. See an excerpt of the code below. Basically, the code works. However, when I open the email template "Urlaubsantrag.oft", it is not opened as a "draft" but as an "outbox". Why is that or how do I query it differently?

Private Sub my_Inspector_Activate()
Dim Mail As Outlook.MailItem
Dim objItems As Outlook.ItemProperties

Set Mail = my_Inspector.CurrentItem
Set objItems = Mail.ItemProperties

With Mail
Select Case True
Case InStr(.subject, "Urlaubsantrag")
If objItems.Item("Parent").Value = "Drafts" Then

…do something…

If objItems.Item("Parent").Value = "Outbox" Or _
objItems.Item("Parent").Value = "Postausgang" Then

…do something…
Case … (some another cases)

End Select
End With

ExitProc:
Set mafl_Inspector = Nothing
Set Mail = Nothing
Set objItems = Nothing

End Sub
 
You need to use CreateItemFromTemplate("templatepath"):
Dim objApp As Outlook.Application
Set objApp = Application
Set oMail = objApp .CreateItemFromTemplate("templatepath")

As an FYI, you can use Mail.Parent to get the folder name (objItems.Parent returns the subject)
 
Thank you for your answer, but I don't think that helps me. The template opens with a double click, and that's how it should be, because I want my employees to have it as easy as possible.
Can it make a difference if I query it with "Mail.Parent" or with "objItems.Item("Parent").Value"?
 
The folder a template is "owned" by is Outbox.... so your second If statement should work on it. If you need to do things to messages legitimately in the outbox, save first.

1741267618555.png



Below is the macro I used for testing - if you open a message that is in the outbox, it is still in the outbox after the Save and shouldn't affect the resy of your code.

Code:
Sub TestTemplate()
Dim objApp As Outlook.Application
Dim Mail As Outlook.MailItem
Dim objItems As Outlook.ItemProperties
    Set objApp = Application

Set Mail = objApp.ActiveInspector.CurrentItem
Set objItems = Mail.ItemProperties

With Mail
Mail.Save
MsgBox "In Folder: " & objItems.Item("Parent").Value
'MsgBox objItems.Parent ' subject

If objItems.Item("Parent").Value = "Drafts" Then
MsgBox "The message is in Drafts"
End If

If objItems.Item("Parent").Value = "Outbox" Then
MsgBox "processing the If statement"
End If


End With

Set Mail = Nothing
Set objItems = Nothing

End Sub
 
Many thanks, that could help me...
 
Similar threads
Thread starter Title Forum Replies Date
L OFT file problem Using Outlook 5
H URL's don't work in .oft file Using Outlook 1
2 Create an email brochure - oft file? Using Outlook 3
J Add an Attachment Using an Array and Match first 17 Letters to Matching Template .oft to Send eMail Outlook VBA and Custom Forms 2
JorgeDario Template oft that contains VBScript Is not running Using Outlook 1
D forward email with attachment using .oft Using Outlook 3
airtas oft templates not sending changes Using Outlook 2
J Outlook .oft files Using Outlook 5
M VBA Send Sales reports using .oft files, originate in Outlook or Excel? Using Outlook 5
W Broken Folder Loop - Outlook 2007 (.oft files) Using Outlook 2
C Custom .oft / Printing Issue(s) Using Outlook 1
V New problem, .oft extentions in Outlook 2013 Using Outlook 5
F CAN'T SAVE OUTLOOK 2010 E-MAIL TEMPLATE (.oft) Using Outlook 1
N How to automatically update all fields in an Outlook message template (OFT)? Using Outlook 9
M Opening oft Files Using Outlook 2
R Outlook Rules and OFT templates Outlook VBA and Custom Forms 1
P how do I work with oft files in outlook 2007 Outlook VBA and Custom Forms 1
P outlook 2007 - custom buttoms with hyperlinks to oft files Outlook VBA and Custom Forms 1
J How do I send a completed .oft form? Outlook VBA and Custom Forms 4
O How will a new Exchange profile handle existing .ost file stored elsewhere? Using Outlook 3
P Windows 11/Office 365 - can't forward calendar entry as ics file Using Outlook 3
A How to open Excel file saved in Outlook folder? Outlook VBA and Custom Forms 4
R File not found when sending email with attached pdf file Using Outlook 2
Victor_50 Outlook 365 Extract all mail addresses and names from a pst file to csv. Using Outlook 3
E "Cannot display the folder. MS Outlook cannot access the specified file location" Using Outlook 8
M Outlook 365 macro - automatically attach file based on subject line Outlook VBA and Custom Forms 0
S Import pst file into 365 desktop and have it sync one Using Outlook.com accounts in Outlook 2
T Cannot open .pst file Using Outlook 2
D DB/Object/Record vs File/List/Range Terminology Outlook VBA and Custom Forms 0
Rob Can't save MailItem because the message changed in .pst file Outlook VBA and Custom Forms 0
C Advanced search terms for "Outlook Data File" Using Outlook 1
G Save emails as msg file from Outlook Web AddIn (Office JS) Outlook VBA and Custom Forms 0
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
E Save Selected Email Message as .msg File - digitally sign email doesn't works Outlook VBA and Custom Forms 1
W Outlook 365 File access denied attempting to import .pst Using Outlook 6
P Copying ALL calendar entries from Calender in PST file to IMAP OST file? Using Outlook 1
R Saving Emails and Attachments as .msg file Using Outlook 3
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
W Create a Quick Step or VBA to SAVE AS PDF in G:|Data|Client File Outlook VBA and Custom Forms 1
Wotme create email only data file Using Outlook 1
C "The linked image cannot be displayed. The file may have been moved, renamed, or deleted. Verify that the link points to the correct file location" Using Outlook 1
L Restoring Outlook from backup pst file Using Outlook 5
W Transfer Outlook 2016 autocomplete file to Outlook 2007 Using Outlook 1
V Backup Calendar, Contacts, Tasks in an POP3 data file Using Outlook 3
DoctorJellybean Use OST file location for fresh installation? Using Outlook 1
HarvMan Exporting IMAP OST file to PST Using Outlook 5
P File Picker for attachment Outlook VBA and Custom Forms 0
D Forwarding email based on the attachment file type and specific text found on the attachment file name Outlook VBA and Custom Forms 1
N File Picker for attachment Outlook VBA and Custom Forms 2
N Save Selected Email Message as .msg File Outlook VBA and Custom Forms 12

Similar threads

Back
Top