![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
I'm trying to do something which surely isn't that difficult!
It will be part of a macro in Excel and what I want to do is copy a range from the activesheet and then paste this into the body of an Outlook e-mail.Here's the code: Private OutApp As Object Private OutMail As Object Private NS As Object Sub UpdateMail() Application.screenupdating = False Application.EnableEvents = False 'put info on the clipboard ThisWorkbook.Sheets("Pivots").Range("B5:C6").Copy ' Call OpenOutlook Set OutMail = OutApp.CreateItem(0) With OutMail .To = "Tester" .Subject = "Solve this one" 'take info from the clipboard .body = ClipBoard.GetText ' .Display End With Set OutMail = Nothing Set OutApp = Nothing Set NS = Nothing Application.screenupdating = true Application.EnableEvents = True End Sub Private Function OpenOutlook() On Error Resume Next Set OutApp = GetObject(, "Outlook.Application") If Err.Number = 429 Then Set OutApp = CreateObject("Outlook.Application") Set NS = OutApp.GetNamespace("MAPI") NS.Logon End If On Error GoTo 0 End Function I'm happy that the copy method in Excel moves the info to the clipboard but how do I extract it and paste it into the body of the mail. Any help greatly appreciated Jason |
#2
|
|||
|
|||
![]()
I've just been playing with something similar but simpler: I wanted to
have a button to insert plain text (rather than formatted text) when editing in HTML. I achieved it using sendkeys for the paste action (yuck!!). However, the getting the string from the clipboard should work for you nonetheless. See below code. HTH Gman Sub PasteAsPlainText() 'need to clean out clipboard - so get text and then put it back fcnLoadStringIntoClipboard (fcnGetStringFromClipboard) SendKeys "^v" End Sub Function fcnLoadStringIntoClipboard(myString As String) Dim DataObj As MSForms.DataObject Set DataObj = New MSForms.DataObject On Error Resume Next 'In case empty DataObj.SetText Text:=myString DataObj.PutInClipboard On Error GoTo 0 Set DataObj = Nothing End Function Function fcnGetStringFromClipboard() As String Dim DataObj As MSForms.DataObject Set DataObj = New MSForms.DataObject On Error Resume Next 'In case empty DataObj.GetFromClipboard fcnGetStringFromClipboard = DataObj.GetText(1) On Error GoTo 0 Set DataObj = Nothing End Function WhytheQ wrote: I'm trying to do something which surely isn't that difficult! It will be part of a macro in Excel and what I want to do is copy a range from the activesheet and then paste this into the body of an Outlook e-mail.Here's the code: Private OutApp As Object Private OutMail As Object Private NS As Object Sub UpdateMail() Application.screenupdating = False Application.EnableEvents = False 'put info on the clipboard ThisWorkbook.Sheets("Pivots").Range("B5:C6").Copy ' Call OpenOutlook Set OutMail = OutApp.CreateItem(0) With OutMail .To = "Tester" .Subject = "Solve this one" 'take info from the clipboard .body = ClipBoard.GetText ' .Display End With Set OutMail = Nothing Set OutApp = Nothing Set NS = Nothing Application.screenupdating = true Application.EnableEvents = True End Sub Private Function OpenOutlook() On Error Resume Next Set OutApp = GetObject(, "Outlook.Application") If Err.Number = 429 Then Set OutApp = CreateObject("Outlook.Application") Set NS = OutApp.GetNamespace("MAPI") NS.Logon End If On Error GoTo 0 End Function I'm happy that the copy method in Excel moves the info to the clipboard but how do I extract it and paste it into the body of the mail. Any help greatly appreciated Jason |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Annoying Outlook Calendar problem | Anders Biro | Outlook - General Queries | 5 | April 27th 06 05:27 PM |
Annoying Popup while Deleting NG threads | Raoul | Outlook Express | 5 | April 1st 06 11:32 AM |
Annoying telephone number formatiing | Alphonse | Outlook - Installation | 4 | April 1st 06 06:24 AM |
Annoying Little Yellow Box | Leonard M. Wapner | Outlook Express | 3 | March 19th 06 02:22 AM |
Annoying Message shows | Bob | Outlook - General Queries | 3 | February 11th 06 08:20 PM |