Results 1 to 5 of 5

Thread: [RESOLVED] Sendkeys from Excel to Outlook

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    69

    Resolved [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

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2007
    Posts
    69

    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.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Sendkeys from Excel to Outlook

    Ok, yes its not usually something net admins like to have, bypassing any security is usually forbidden.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width