[RESOLVED] Sendkeys from Excel to Outlook
Im sending an email from an excel VBA and our internal IT guys have instigated a security classifycation requirement for all emails.
When you Send you get a box with a list and you have to choose a level of security. (I work in a big govt dept).
I am trying to set that with "Sendkeys" but I only get error message "Object doesnt support this property or code." Should Outlook support Sendkeys?
When running it the box has focus and you only need to hit DOWN DOWN ENTER to get what I want. then it continues. This code is mostly from this forum.
Code:
Private Sub CommandButton3_Click()
'Add a reference to MS Outlook xx.0 Object Library
Dim oApp As Outlook.Application
Dim oEmail As Outlook.MailItem
Set oApp = New Outlook.Application
Set oEmail = oApp.CreateItem(olMailItem)
With oEmail
.To = "[email protected]"
.Subject = "What ever your subject is"
.BodyFormat = olFormatPlain
.Body = "...text here..."
.Importance = olImportanceHigh
'.ReadReceiptRequested = True
.Recipients.ResolveAll
.Save
.Display 'Show the email message and allow for editing before sending
.SendKeys "{DOWN}{DOWN}{ENTER}", True
.Send 'You can automatically send the email without displaying it.
End With
Set oEmail = Nothing
'oApp.Quit
Set oApp = Nothing
End Sub
This all works fine appart from needing to set the security. It comes up and you can manually select it and then it proceeds.
If I put the .Sendkeys line after .Send it doesnt get that far before needing input to the security box.
any ideas
Re: Sendkeys from Excel to Outlook
Thats because the Security Prompt is modal so anything after the .SEnd line will stop and not be processed until you dismiss the dialog. Try using Click Yes instead.
Re: Sendkeys from Excel to Outlook
Thanks for the thought but I didnt get to try it.
'Security' decided it needs to be done manually by a person anyway.
Makes sense.
Re: [RESOLVED] Sendkeys from Excel to Outlook
Ok, yes its not usually something net admins like to have, bypassing any security is usually forbidden.
Re: [RESOLVED] Sendkeys from Excel to Outlook
SendKeys is a command from VBA Application.
The error message tells you that SendKeys is not a property or method of oEmail.
You cannot use
Code:
With oEmail
.SendKeys "{DOWN}{DOWN}{ENTER}", True
It must be without the "dot":
Code:
SendKeys "{DOWN}{DOWN}{ENTER}", True