VBA to insert text in subject line in Outlook

Jesper E Magnussen
Jesper E Magnussen used Ask the Experts™
on
Hi,

Found a bit of VBA code to place text in the subject line of Outlook:

Sub New_Subject_Email()
Dim MItem As MailItem
Set MItem = Application.CreateItem(olMailItem)
MItem.subject = "36355 XXXXXXXXXX - "
MItem.Display
End Sub

It Works, but I would love to have the cursor ready (blinking) to type after the "36355 XXXXXXXXXX - " when I use the TAB key to activate the Subject line.

How would I change the VBA code accordingly?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
President / Owner CARDA Consultants Inc.
Distinguished Expert 2018
Commented:
Have you seen https://www.datanumen.com/blogs/default-cursor-subject-field-creating-new-message-outlook/ and then use SelStart to postion the cursor.  This is untested though.

Another alternative would be to use APIs that I identify the control Hwnd so you can interact with it.
Karen FalandaysTraining Specialist

Commented:
I am curious as to why you wouldn't just use a quick step to autofill the subject and any other info
Jesper E MagnussenProject Director

Author

Commented:
Hi Daniel,

Checked it out, problem is that you come directly to the subject line, I would rather start with receiver name, use TAB key to move downwards and when in subject line, cursor ready to start typing after the pre-typed text.

I'm a project director and have several projects with different project numbers and names, having always project number and name I can sort the mails automatically, hence the question.

Brgds
Jesper
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Jesper E MagnussenProject Director

Author

Commented:
Hi Karen,

Quick  step works fine, but as above, I would like to have cursor ready to type when I, by using TAB key, reaches down to Subject line and have cursor ready after the text already inserted by code.

Brgds
Jesper
Jesper E MagnussenProject Director

Author

Commented:
HI,

Above code works fine, only I need the addition to get the cursor ready to type and the end of the text already placed in the subject line, when the subject line gets focus by jumping down using TAB key.

Brgds
Jesper
Jesper E MagnussenProject Director

Author

Commented:
No solution found for having cursor ready at the end of the pre-printed text in the subject line.
Daniel PineaultPresident / Owner CARDA Consultants Inc.
Distinguished Expert 2018

Commented:
As I originally stated, I think you'd have to get into using windows APIs for this.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial