Auto Send Email via Excel Userform

jamieleeuk

Board Regular
Joined
Feb 9, 2009
Messages
99
Is it possible to send a screenshot of a userform via an email to a specific email address once a button has been pressed on said userform?
 
Hello Leith,

I would like to send in the body of email. I have tried both way, but cannot be successfull, resulted in a scrap-workbook :)

Thanks for your help
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hello Leith,

I think I have mistake combining two codes together. Here are two codes I am working on. First one is "ScreenCapture" to copy the active window into clipboard and second one is "emailimage" to paste clipboard to outlook mail. If I run them seperately with two buttons (click first then second), they do what I want. However I cannot combine them to run just with 1 click (I have used Call code, but screencapture is not seems to work properly :( )

1.Code: Screencapture
Code:
'Written: October 23, 2008
'Author:  Leith Ross
'Summary: Capture the screen image as a picture. VBA SendKeys won't do this function.
'         It can be done using the WIndows API. The image is automatically transfered
'         to the clipboard.

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
  bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SNAPSHOT = &H2C
Private Const VK_MENU = &H12

Sub ScreenCapture()
    keybd_event VK_MENU, 0, 0, 0
    keybd_event VK_SNAPSHOT, 0, 0, 0
    keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
    keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
End Sub

2.Code: Pasting clipboard to email
Code:
Sub emailimage()

Dim OutApp As Object
Dim OutMail As Object

'Shift-Print Screen
Application.SendKeys "(%{1068})"

On Error Resume Next

'Prepare the email
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
    
    With OutMail
        .To = "youremail@test.com"
        .Subject = "Subject line"
        .Display
    
        Application.SendKeys "(^v)"
        
    End With
On Error GoTo 0

OutApp.Session.Logoff
Set OutMail = Nothing
Set OutApp = Nothing

End Sub

3. Runboth:

Code:
Sub Runboth()
Call ScreenCapture
Call emailimage
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,222,564
Messages
6,166,818
Members
452,074
Latest member
Alexinho

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top