A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

VBA Clipboard Cut & Paste from Excel to Outlook



 
 
Thread Tools Search this Thread Display Modes
  #11  
Old February 1st 07, 09:32 AM posted to microsoft.public.outlook.program_vba
andy
external usenet poster
 
Posts: 122
Default VBA Clipboard Cut & Paste from Excel to Outlook

Thanks again Michael - I'm obviously not famailar wit Doc objects ( normally
work with Access, Excel and Outook).

I have tried this code but get error a compliatio error 'Type error' on Set
objPara = "Some Text" :-

' Other Dims
Dim objPara As Word.Paragraph

Set objEmail = objDrafts.Items.Add

Set Doc = objEmail.GetInspector.WordEditor

Set objPara = "Some Text"

objPara.Copy
wdRn.Paste

Set wdRn = Doc.Range.End

Set xlRn = Range(Cells(aa, 4), Cells(bb, 17))
xlRn.Copy

wdRn.Paste

There must be an easy way to insert some text with Range object? I've tried
several properties. The code line Set wdRn = Doc.Range.End also fails.

"Michael Bauer [MVP - Outlook]" wrote:


Yes, as I mentioned earlier use Word's object model, that is Document.Range
instead of MailItem.Body. First insert some text, then set the Range to the
Document's end, paste the table, set the Range to its end again and add more
text.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Wed, 31 Jan 2007 16:27:01 -0800 schrieb Andy:

Excellent - That worked fine. The Draft email was created and the range

was
pasted into the Draft email complete with formatting - well done.

One last thing. It would be nice to insert some text before and after the
pasted table.

After the objEmail is created I have experimented with :-

objEmail.Body.PrintText Text:="Please find table below :-"
objEmail.Body.PrintParagraph
wdRn.Paste ' to paste in the Word Range
objEmail.Body.PrintParagraph
objEmail.Body.PrintText Text:="Regards etc."

but I get 424 - 'Object Required'

any last thoughts?

Thanks.


"Michael Bauer [MVP - Outlook]" wrote:



ActiveInspector exists if an item is opened. In your code call

Set Doc=objEmail.Getinspector.WordEditor

after objEmail is being created.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)

Am Wed, 31 Jan 2007 01:32:01 -0800 schrieb Andy:

Thanks again Michael.

I think the key problem I am having is in this line of code in your
example :-

Set Doc = Application.ActiveInspector.WordEditor

It works fine in the context of your example but if I create a Draft
folder
item as below, it fails :-

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.Worksheet
Dim xlRn As Excel.Range

Set objOutlook = New Outlook.Application

Set Doc = objOutlook.ActiveInspector.WordEditor

' 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 wdRn = Doc.Range

Set Xl = GetObject(, "Excel.Application")
Set Ws = Xl.Workbooks("Mappe1.xls").Worksheets(1)

Set xlRn = Ws.Range("b2", "c6")
xlRn.Copy

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 worksheet
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

Any further thoughts - we are almost there? Maybe all this code could

be
driven from Outlook.


"Michael Bauer [MVP - Outlook]" wrote:


From Excel the Application object refers to Excel. So you need a

variable
for the Outlook Application object and either use GetObject, or, if
Outlook
doesn't run, CreateObject to get the reference to Outlook.

Please note, that the WordEditor property is protected. Calling that
property without having Outlook's instrinsic Application object will
prompt
a security dialog.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Tue, 30 Jan 2007 10:16:02 -0800 schrieb Andy:

Cool - That worked fine but your example has to be run from Outlook

with
an
New email open.

I am trying to run the whole thing from Excel opening up Outlook as an
Object and creating several Draft emails to cut &paste into each.

Could you provide any more guidance?

Thanks.

"Michael Bauer [MVP - Outlook]" wrote:


The message must be in HTML, of course. RTF may also work but only if
your
receiver uses Outlook, too.

The shown line wouldn't cause the error 'Can't set object outside a
With
Block error'. So there must be more around it that you doesn't show

us.

Here's a complete sample. It's assumed that the HTML e-mail and
workbook
'Mappe1.xls' are opened yet and copies the range from cell "B2" to
"C6":

http://www.vboffice.net/sample.html?...1&cmd=showitem

Then please see Word's object model. You can exactly determine the
Range
before calling its Paste method. Or you paste the table first, then
write
additional text at the beginning of the document and some at it's

end.

Outlook's object model doesn't allow you to place the cursor into an
e-mail's body. For instance, you could call the Insert commadn via

the
toolbar, but if the cursor is currently in the To field then the
clipboard
content gets inserted into that field.

If you don't want to use Word as mail editor then you need a
workaround.
Then I'd recommend Redemption (www.dimastr.com) to set the cursor
position.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!

http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Mon, 29 Jan 2007 06:58:03 -0800 schrieb Andy:

Thanks Michael,

Your idea sounds good but I am not sure how exactly to code your
suggestion.

I tried :-

Set Doc=objOutlook.ActiveInspector.WordEditor (where objOutlook is a
new
Outlook appliaction object)

but I got a 'Can't set object outside a With Block error'

My other confusion is your line :-

Doc.Range.Paste

Yes - the syntax is valid but how would it relate to the building of
an
Outlook message for my Draft email? I am setting the objEmail.Body

to
be
a
string hopeflly including the table that I am trying to cut and

paste.
In
other words, I don't just need the table copying in, but I need to

put
some
fixed words around the table as well.

I think my main problem relates to Outlook. When building a message

in
Excel
VBA the message ends up being Plain text which is messing up the
formatting
of the cut & paste table. I need a way of letting Outlook know that

it
is
HTML or Rich Text format.

Happy to include my code so far if you need it.

Thanks.



"Michael Bauer [MVP - Outlook]" wrote:


With Word as mail editor you can use its object model to insert the
clipboard content. Like this:

Dim Doc as Word.Document
Set Doc=Application.ActiveInspector.WordEditor
Doc.Range.Paste

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!

http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Sun, 28 Jan 2007 16:47:00 -0800 schrieb Andy:

An unusual one this one but please read on.

If I manually copy a range of cells from an Excel worksheet and

then
paste
into a Draft email in Outlook (My Outlook 2003 uses HTML as draft
format
with
Word as editor) the resulting pasted cells look fine - colors and
formatting
are maintained.

Ads
  #12  
Old February 2nd 07, 05:59 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default VBA Clipboard Cut & Paste from Excel to Outlook


There's no difference between Excel Word & Co.: You can't set an object
variable to a non-object.

Please look into the obejct browser (F2) and switch from All Libraries to
Word. Select the Range class in the left pane and you can view all its
properties, methods etc. in the right pane.

There you'll see that the End property returns a Long value and not an
object. You can use that and the Start property to set the range. That is
also explained if you select one of the properties and press F1.

A sample: If you set Start=0 and End=0 then the cursor is at the beginning
of the document. Now you can write some text into Range.Text. Then set the
Range to the end and paste the table etc.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Thu, 1 Feb 2007 01:32:00 -0800 schrieb Andy:

Thanks again Michael - I'm obviously not famailar wit Doc objects (

normally
work with Access, Excel and Outook).

I have tried this code but get error a compliatio error 'Type error' on

Set
objPara = "Some Text" :-

' Other Dims
Dim objPara As Word.Paragraph

Set objEmail = objDrafts.Items.Add

Set Doc = objEmail.GetInspector.WordEditor

Set objPara = "Some Text"

objPara.Copy
wdRn.Paste

Set wdRn = Doc.Range.End

Set xlRn = Range(Cells(aa, 4), Cells(bb, 17))
xlRn.Copy

wdRn.Paste

There must be an easy way to insert some text with Range object? I've

tried
several properties. The code line Set wdRn = Doc.Range.End also fails.

"Michael Bauer [MVP - Outlook]" wrote:


Yes, as I mentioned earlier use Word's object model, that is

Document.Range
instead of MailItem.Body. First insert some text, then set the Range to

the
Document's end, paste the table, set the Range to its end again and add

more
text.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Wed, 31 Jan 2007 16:27:01 -0800 schrieb Andy:

Excellent - That worked fine. The Draft email was created and the range

was
pasted into the Draft email complete with formatting - well done.

One last thing. It would be nice to insert some text before and after

the
pasted table.

After the objEmail is created I have experimented with :-

objEmail.Body.PrintText Text:="Please find table below :-"
objEmail.Body.PrintParagraph
wdRn.Paste ' to paste in the Word Range
objEmail.Body.PrintParagraph
objEmail.Body.PrintText Text:="Regards etc."

but I get 424 - 'Object Required'

any last thoughts?

Thanks.


"Michael Bauer [MVP - Outlook]" wrote:



ActiveInspector exists if an item is opened. In your code call

Set Doc=objEmail.Getinspector.WordEditor

after objEmail is being created.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)

Am Wed, 31 Jan 2007 01:32:01 -0800 schrieb Andy:

Thanks again Michael.

I think the key problem I am having is in this line of code in your
example :-

Set Doc = Application.ActiveInspector.WordEditor

It works fine in the context of your example but if I create a Draft
folder
item as below, it fails :-

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.Worksheet
Dim xlRn As Excel.Range

Set objOutlook = New Outlook.Application

Set Doc = objOutlook.ActiveInspector.WordEditor

' 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 wdRn = Doc.Range

Set Xl = GetObject(, "Excel.Application")
Set Ws = Xl.Workbooks("Mappe1.xls").Worksheets(1)

Set xlRn = Ws.Range("b2", "c6")
xlRn.Copy

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 worksheet
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

Any further thoughts - we are almost there? Maybe all this code could

be
driven from Outlook.


"Michael Bauer [MVP - Outlook]" wrote:


From Excel the Application object refers to Excel. So you need a

variable
for the Outlook Application object and either use GetObject, or, if
Outlook
doesn't run, CreateObject to get the reference to Outlook.

Please note, that the WordEditor property is protected. Calling that
property without having Outlook's instrinsic Application object will
prompt
a security dialog.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!

http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Tue, 30 Jan 2007 10:16:02 -0800 schrieb Andy:

Cool - That worked fine but your example has to be run from Outlook

with
an
New email open.

I am trying to run the whole thing from Excel opening up Outlook as

an
Object and creating several Draft emails to cut &paste into each.

Could you provide any more guidance?

Thanks.

"Michael Bauer [MVP - Outlook]" wrote:


The message must be in HTML, of course. RTF may also work but only

if
your
receiver uses Outlook, too.

The shown line wouldn't cause the error 'Can't set object outside a
With
Block error'. So there must be more around it that you doesn't show

us.

Here's a complete sample. It's assumed that the HTML e-mail and
workbook
'Mappe1.xls' are opened yet and copies the range from cell "B2" to
"C6":

http://www.vboffice.net/sample.html?...1&cmd=showitem

Then please see Word's object model. You can exactly determine the
Range
before calling its Paste method. Or you paste the table first, then
write
additional text at the beginning of the document and some at it's

end.

Outlook's object model doesn't allow you to place the cursor into

an
e-mail's body. For instance, you could call the Insert commadn via

the
toolbar, but if the cursor is currently in the To field then the
clipboard
content gets inserted into that field.

If you don't want to use Word as mail editor then you need a
workaround.
Then I'd recommend Redemption (www.dimastr.com) to set the cursor
position.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!

http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Mon, 29 Jan 2007 06:58:03 -0800 schrieb Andy:

Thanks Michael,

Your idea sounds good but I am not sure how exactly to code your
suggestion.

I tried :-

Set Doc=objOutlook.ActiveInspector.WordEditor (where objOutlook is

a
new
Outlook appliaction object)

but I got a 'Can't set object outside a With Block error'

My other confusion is your line :-

Doc.Range.Paste

Yes - the syntax is valid but how would it relate to the building

of
an
Outlook message for my Draft email? I am setting the objEmail.Body

to
be
a
string hopeflly including the table that I am trying to cut and

paste.
In
other words, I don't just need the table copying in, but I need to

put
some
fixed words around the table as well.

I think my main problem relates to Outlook. When building a

message
in
Excel
VBA the message ends up being Plain text which is messing up the
formatting
of the cut & paste table. I need a way of letting Outlook know

that
it
is
HTML or Rich Text format.

Happy to include my code so far if you need it.

Thanks.



"Michael Bauer [MVP - Outlook]" wrote:


With Word as mail editor you can use its object model to insert

the
clipboard content. Like this:

Dim Doc as Word.Document
Set Doc=Application.ActiveInspector.WordEditor
Doc.Range.Paste

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!

http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Sun, 28 Jan 2007 16:47:00 -0800 schrieb Andy:

An unusual one this one but please read on.

If I manually copy a range of cells from an Excel worksheet and

then
paste
into a Draft email in Outlook (My Outlook 2003 uses HTML as

draft
format
with
Word as editor) the resulting pasted cells look fine - colors

and
formatting
are maintained.

  #13  
Old May 13th 08, 05:07 AM posted to microsoft.public.outlook.program_vba
Jyothi Muddam
external usenet poster
 
Posts: 1
Default VBA Clipboard Cut & Paste from Excel to Outlook

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.Worksheet
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 worksheet
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
  #14  
Old May 13th 08, 06:41 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default VBA Clipboard Cut & Paste from Excel to Outlook



In that line the error means Doc isn't set. Probably you don't use Word as
e-mail editor, but that is necessary for this code to work.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool:
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Mon, 12 May 2008 21:07:25 -0700 schrieb Jyothi Muddam:

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.Worksheet
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 worksheet
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

  #15  
Old May 14th 08, 02:23 AM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 1
Default VBA Clipboard Cut & Paste from Excel to Outlook

Thanks Michael,

You are right. Thsi option is disabled in my outlook 2003
automatically.
Is there anyway that I can enable this option.

Actually I don't want to use Word as editor. For this you suggested
for using Redemption.
My clients also cna have different verison of outlook i.e. outlook XP/
2000/2003/2007 etc.
At my development server I am running Outlook 2003.

Cna I have any help on this please.
I am trying to use Redemption.RDOs. But not having much expertise in
VBA I lost.

Can I have any code sample for this please.

Really appreciate your time.

With Thanks.

Jyothi.


On May 13, 5:41*pm, "Michael Bauer [MVP - Outlook]"
wrote:
In that line the error means Doc isn't set. Probably you don't use Word as
e-mail editor, but that is necessary for this code to work.

--
Best regards
Michael Bauer - MVPOutlook

* :OutlookCategories? Category Manager Is Your Tool:
* : http://www.vboffice.net/product.html?pub=6&lang=en

Am Mon, 12 May 2008 21:07:25 -0700 schrieb Jyothi Muddam:





Hi Michael,


I am trying to follow the exactly the smae code which you given here.


Private Sub Test()


Dim objOutlook AsOutlook.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.Worksheet
Dim xlRn As Excel.Range


Set objOutlook = NewOutlook.Application


' Open theoutlookdrafts folder


Set objDrafts = objOutlook.Session.GetDefaultFolder(olFolderDrafts )


If objDrafts = "Drafts" Then


'Createnew 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, maybeusinga"
DataObject.GetFromClipboard ""
strTitle = "Excel toOutlookPaste"
strTo = Ws.Range("a1", "a1") ' email adresss in A1 in worksheet
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 amusingoutlook2003 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- Hide quoted text -


- Show quoted text -


  #16  
Old May 14th 08, 06:32 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default VBA Clipboard Cut & Paste from Excel to Outlook



If you don't want to use Word, you have to use the Redemption. Please look
at Dmitry's site (http://www.dimastr.com/redemption/safeinspector.htm),
there're tons of samples.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool:
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Tue, 13 May 2008 18:23:22 -0700 (PDT) schrieb
:

Thanks Michael,

You are right. Thsi option is disabled in my outlook 2003
automatically.
Is there anyway that I can enable this option.

Actually I don't want to use Word as editor. For this you suggested
for using Redemption.
My clients also cna have different verison of outlook i.e. outlook XP/
2000/2003/2007 etc.
At my development server I am running Outlook 2003.

Cna I have any help on this please.
I am trying to use Redemption.RDOs. But not having much expertise in
VBA I lost.

Can I have any code sample for this please.

Really appreciate your time.

With Thanks.

Jyothi.


On May 13, 5:41*pm, "Michael Bauer [MVP - Outlook]"
wrote:
In that line the error means Doc isn't set. Probably you don't use Word

as
e-mail editor, but that is necessary for this code to work.

--
Best regards
Michael Bauer - MVPOutlook

* :OutlookCategories? Category Manager Is Your Tool:
* : http://www.vboffice.net/product.html?pub=6&lang=en

Am Mon, 12 May 2008 21:07:25 -0700 schrieb Jyothi Muddam:





Hi Michael,


I am trying to follow the exactly the smae code which you given here.


Private Sub Test()


Dim objOutlook AsOutlook.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.Worksheet
Dim xlRn As Excel.Range


Set objOutlook = NewOutlook.Application


' Open theoutlookdrafts folder


Set objDrafts = objOutlook.Session.GetDefaultFolder(olFolderDrafts )


If objDrafts = "Drafts" Then


'Createnew 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, maybeusinga"
DataObject.GetFromClipboard ""
strTitle = "Excel toOutlookPaste"
strTo = Ws.Range("a1", "a1") ' email adresss in A1 in worksheet
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 amusingoutlook2003 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- Hide quoted text -


- Show quoted text -

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Clipboard gets empty by itself, cleared clipboard, copy paste doesn't work, outlook clears clipboard, problems with clipboard - possible solution Jens Hoerburger Outlook - General Queries 0 August 24th 06 02:44 PM
HTML cut-and-paste bug [email protected] Outlook and VBA 0 April 20th 06 03:26 PM
Cut & Paste Outlook Display Names Into To Field Display As ; PJ Outlook - Using Contacts 0 March 9th 06 04:16 PM
Cut and Paste Outlook and all settings BEEJAY Outlook - Installation 1 March 5th 06 10:31 PM
Outlook should allow cut and paste when creating message rules. exflier Outlook - General Queries 1 January 18th 06 03:14 PM


All times are GMT +1. The time now is 03:39 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.