Results 1 to 6 of 6

How to activate Outlook mail item in order to send keys

Threaded View

  1. #1
    Registered User
    Join Date
    02-17-2018
    Location
    The Woodlands, TX
    MS-Off Ver
    Windows 10
    Posts
    4

    How to activate Outlook mail item in order to send keys

    After creating the email, I need to paste copied range to the body of the email. Then copy another range and paste below. Problem is that if other application or folders are up, the email window opens behind something and doesn't have the focus. So the graphs in the range I am copying don't get pasted to the body. The second time I run the macro, though, it works because the email displays in front of everything. How can I force the email to have the focus every time?

    Sub Email_to_Distribution()
    '
    ' Email_to_Distribution Macro
    '
    
    '
         Application.ScreenUpdating = False
         Dim objOutlook As Object
         Dim objMail As Object
         Dim rngTo As Range
         Dim rngSubject As Range
         Dim rngBody As Range
         Dim rngAttach As Range
         Dim intFiles As Integer
     
        Set objOutlook = CreateObject("Outlook.Application")
        Set objMail = objOutlook.CreateItem(0)
        
        With ActiveSheet
             Set rngTo = .Range("AP2")
             Set rngSubject = .Range("AP3")
             intFiles = .Range("AP4").Value
             Set rngAttach = .Range("AP7").Resize(intFiles, 1)
         End With
         
        With objMail
             .to = rngTo.Value
             .Subject = rngSubject.Value
             For Each rngFile In rngAttach
                .Attachments.Add rngFile.Value
             Next rngFile
             .Display
    
         End With
         Set objOutlook = Nothing
         Set objMail = Nothing
         Set rngTo = Nothing
         Set rngSubject = Nothing
         Set rngBody = Nothing
         Set rngAttach = Nothing
         Set rngFile = Nothing
         
         Application.ScreenUpdating = True
         
         'minimize Excel window
         Application.WindowState = xlMinimized
         
        'copy first 6 graphs and paste to email
         Range("A1:AG94").Select
         Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
         SendKeys "{ENTER}"
         SendKeys "^v"
         SendKeys "{ENTER}"
        'copy last 6 graphs and paste to email
         Range("A95:AG182").Select
         Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
         SendKeys "^v"
         Range("AN2").Select
         Application.Wait (Now + TimeValue("0:00:01"))
        'maximize Excel window
         Application.WindowState = xlMaximized
    End Sub
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 02-18-2018 at 09:52 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Vba--excel to send outlook mail item
    By lafleuk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-21-2016, 07:24 AM
  2. [SOLVED] Code to send mail copying from Excel to a new outlook mail.
    By paz1987 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-11-2015, 07:54 AM
  3. Outlook 2007, Referencing mail Item created from outlook template
    By thusidie in forum Outlook Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2014, 04:33 PM
  4. Send Mail with Send Keys
    By MusicMan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-04-2014, 10:48 AM
  5. Send e-mail with image on body (.html) on e-mail manager <> outlook
    By mariotnc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-05-2012, 09:28 PM
  6. Activate another window and send keys
    By yellowpower in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-09-2011, 10:13 AM
  7. outlook redemtion macro cant send mail if outlook is not open ?
    By okl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-03-2010, 07:35 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1