Dear All
I aim to take a screenshot of an active Excel window (it is a userform) and send it in the body of a Outlook E-Mail as image with clicking on a commandbutton on userform. I found some codes; however 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 (see attachment: click first ScreenCapture and then emailimage), they do exactly 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, it takes capture of outlook mail: see attachment and click RunBoth button). How can I combine them together or run them properly with just 1 click on userform?
Kitap1.xlsm
Thanks in advance
CODE-1: ScreenCapture (to take screenshot of active window)
CODE-2: emailimage (to paste clipboard to a new mail and send/display it)'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, 1, 0, 0 keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0 keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0 End Sub
CODE-3: Runboth (to run two different macro with 1 click)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
Sub Runboth() Call ScreenCapture Call emailimage End Sub
Last edited by huseyinkasirga; 02-10-2012 at 06:14 AM. Reason: Attached File
Hello All,
Does anyone have any idea for solution?
Thanks for your support.
I also have attached a simple sample file to make clear what i am telling.
Dear All,
Has nobody any idea about the solution?
Dear All,
Has nobody any idea about the solution?
Hi huseyinkasirga
Let me look at this for a bit. I've successfully done thisand I've successfully been able to embed an image into the Outlook Email body. Let me see what I can do. I'll get back to you.take a screenshot of an active Excel window (it is a userform)
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hi huseyinkasirga
What versions of Excel, Outlook and Word are you running? Your profile indicates 2003 but you attached an .xlsm file.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hello jaslake,
Thank you very much for your attention and support. I am working with 2003 version Office. The file that I have uploaded was prepared in Office 2010, because I have prepared and uploaded that example from another computer. However I am working with 2003 to create a userform and also the users are using 2003.
Thanks in advance
Last edited by huseyinkasirga; 02-09-2012 at 02:42 PM.
Just now I have updated the attachment with 2003 version and created a simple userform to make us able to try codes. It seems that problem is maybe paste code, because ScreenCapture code copies the image to clipboard, emailimage code is starting outlook with a new mail, but the image is not pasted![]()
Last edited by huseyinkasirga; 02-09-2012 at 02:45 PM.
Best Regards,
Kasirga
Hi Kasirga
My research has indicated one cannot do a copy/paste into the Outlook Email Body. The code in the attached overcomes that and is attributed to Leith Ross and Ivan F Moala (http://www.xcelfiles.com/EmailImg.html). I've merely adapted it to my needs and to the requests of OP's. There are other ways to do this but I've not been successful implementing these other ways in pre-2007 Excel/Outlook.
Please note...you'll need to set these references in VBA (or whatever version you have available) References.jpg
Play with it...let me know of issues.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hello John,
It really worked also for me. Thank you very much for your support![]()
Best Regards,
Kasirga
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks