VBA Clipboard Cut & Paste from Excel to Outlook
- From: Jyothi Muddam
- Date: Mon, 12 May 2008 21:07:25 -0700
Hi Michael,
I am trying to follow the exactly the smae code which you given here.
Private Sub Test()
Dim objOutlook As Outlook.Application
Dim objOutlookExp As Object
Dim objDrafts As Object
Dim objEmail As Object
Dim strBody, strTitle, strTo As String
Dim Doc As Word.Document
Dim wdRn As Word.Range
Dim Xl As Excel.Application
Dim Ws As Excel.Work***
Dim xlRn As Excel.Range
Set objOutlook = New Outlook.Application
' Open the outlook drafts folder
Set objDrafts = objOutlook.Session.GetDefaultFolder(olFolderDrafts)
If objDrafts = "Drafts" Then
' Create new email in Drafts folder
Set objEmail = objDrafts.Items.Add
Set Xl = GetObject(, "Excel.Application")
Set Ws = Xl.Workbooks("ColorTest.xls").Worksheets(1)
Set xlRn = Ws.Range("a1", "d139")
xlRn.Copy
Set Doc = objEmail.Getinspector.WordEditor
Set wdRn = Doc.Range
wdRn.Paste
strBody = "This is where I need to paste xlRn, maybe using a"
DataObject.GetFromClipboard ""
strTitle = "Excel to Outlook Paste"
strTo = Ws.Range("a1", "a1") ' email adresss in A1 in work***
objEmail.To = strTo
objEmail.Body = strBody
objEmail.Subject = strTitle
Set objDoc = objEmail.Attachments
objDoc.Add strAttach
' Save email in drafts folder
objEmail.Close olSave
Else
MsgBox "No Drafts Folder"
End If
'-----------------
'This line in the above fails with Object not set error :-
Set Doc = objOutlook.ActiveInspector.WordEditor
'Also the line below needs to paste into the Draft email i.e. into the Body
'of email :-
wdRn.Paste
End Sub
I am getting object not set error @line....
Set wdRn = Doc.Range
I am using outlook 2003 and try to call this from Excel.
Actually, I would like to do this from Visual Basic.
Is there anyway I can get this work please.
Thanks in advance.
Jyothi
.
- Follow-Ups:
- Re: VBA Clipboard Cut & Paste from Excel to Outlook
- From: Michael Bauer [MVP - Outlook]
- Re: VBA Clipboard Cut & Paste from Excel to Outlook
- Prev by Date: Re: Possible to Disable Object Model Guard?
- Next by Date: Re: VBA Clipboard Cut & Paste from Excel to Outlook
- Previous by thread: Possible to Disable Object Model Guard?
- Next by thread: Re: VBA Clipboard Cut & Paste from Excel to Outlook
- Index(es):