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
Bookmarks