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?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hello jamieleeuk,

What is the userform - a worksheet or VBA USerForm?

Sincerely,
Leith Ross
 
Upvote 0
Hello jamieleeuk,

It would be easiest to send the form as an attachment. Will that work for you?

Sincerely,
Leith Ross
 
Upvote 0
Hi JamieLeeuk,

The following code should do what you require.

Code:
Sub PrintTheScreen()
Application.SendKeys "(%{1068})"
DoEvents
End Sub

Hope it helps!

Also it's well worth looking in to usin CDO for sending emails VERY easy to use and below is a very usefull link which explaines how.

http://www.rondebruin.nl/cdo.htm

Good Luck

Mansel160
 
Upvote 0
Hello jamieleeuk,

You can't use the SendKeys method to capture the screen. You need to use the Windows API.
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 imageis 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
Sincerely,
Leith Ross
 
Upvote 0
Hi Leith,

I am very new to VBA but have tested the code above and it really does capture the screen and send it to the clipboard!

Kind regards

Mansel160
 
Upvote 0
Hi Leith,

I was just looking for a solution like you mentioned above. I want to take a screenshot of an active userform and then send it with Outlook to a pre-defined email address automatically when clicked on a command button. A have seen your code above and had some trials. However I have failed with VBA to integrate it with second part I mentioned (sending with email to a predefined address). I am new with VBA. Could you help me about this issue?

Thanks in advance.
 
Upvote 0
Hello huseyin.kasirga,

Did you want to send the picture as an attachment or in the body of the email?
 
Upvote 0

Forum statistics

Threads
1,222,562
Messages
6,166,804
Members
452,073
Latest member
akinch

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