View Single Post
  #3  
Old January 29th 07, 03:58 PM posted to microsoft.public.outlook.program_vba
andy
external usenet poster
 
Posts: 122
Default VBA Clipboard Cut & Paste from Excel to Outlook

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.

OK now to do it in VBA from Excel.

I copy the range of cells into Clipboard with :-

Range(Cells(aa, 4), Cells(bb, 17)).Select
Selection.Copy

I then obtain the contents of Clipboard and place into a String variable
with :-

Set MyData = New DataObject

MyData.GetFromClipboard
strClip = MyData.GetText

I then create an Outloook object within VBA and build a Draft message

using
strClip as part of the Message body.

This all works OK and the Draft message is created but the resulting

pasted
range of cells in the Draft message does not look very good, the values

are
mis-aligned and wrapped around with any color formatting is lost. It does

not
give me the same pretty result as manually cutting and pasting the cells.

Does anyone know how I can preserve the formatting using the VBA method so
that the resulting pasted cells looks as good as the manual method?

Thanks.


Ads