Excel vs Outlook macro

Clefebvre

New Member
Joined
May 29, 2002
Messages
8
Is it possible to do a macro to copy a cell in excel and paste that cell in outlook and return to excel

Thanks
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi,

Try this code. It copies the value of cell A1 to the body of a new message and either displays it or sends it depending on what you want.

Code:
Sub Test()
Dim olApp As Object, olMail As Object

Set olApp = CreateObject("Outlook.Application")
Set olMail = olApp.CreateItem(0)
olMail.To = "Anyone@anywhere.com"
olMail.Body = Range("a1")   'Change to suit your needs

'To display the message use this
olMail.Display

'or to send the message use this
'olMail.Send

'Reactive Excel
AppActivate "Microsoft Excel"


End Sub

Let me know if this suits your needs,

Dan
 
Upvote 0
Thank you Dan, Thats working, but I would like to know how to add someting in the Object field and the C.C. field by excel macro.

Thank in advance.

Claude
 
Upvote 0
under the olmail.To put this
olMail.Cc = "andeveryonelse@everywhere.com"

it will send as Cc
This message was edited by Qroozn on 2002-05-30 18:16
 
Upvote 0
Sorry, forget the last message. Because i use a french version of Office the thing i was looking for was Subject and it work in the macro.

Now How cant i add a attachement file in the macro.
 
Upvote 0
Now How cant i add a attachement file in the macro

You can add attachments. Use this line before you send it:-

olMail.Attachments.Add "C:Your folderYour File.xls"

HTH,
Dan
 
Upvote 0
Hello all,

As a follow up to this question and a similar one here ( http://www.mrexcel.com/board/viewtopic.php?topic=10079&forum=2&3 ) here is something which may help you.

The original code I used above used 'late binding'. This is where the code creates objects without knowing in advance what they might be - such as the Outlook application itself and the message. You may notice that when I dimensioned the variables I declared them as Object -

Dim olApp As Object, olMail As Object

Now a better way of doing this is to use early binding. This is where you include the Outlook object library in your Excel project. You do this by clicking Tools, References in the VB Editor and choosing Microsoft Outlook Object Library. You can the dimension your variables like this:-

Dim olApp As Outlook.Application, olMail as Outlook.MailItem

This has several advantages:-

  • The code will run quicker.
  • Any errors can be picked up at design time by clicking Debug, Compile e.g. invalid constant names.
  • Perhaps most importantly you can now list all the members of an Outlook object in the same way you can an Excel object. E.g. change the above code so that it includes references to the Outlook library and dimension the variables as above. Now when you hit the . of olMail. you will be presented with a dropdown list of all properties and methods of the MailItem object (there are loads) and you can do practically anything to a message that you could do if you were in Outlook itself. Also, the objects will all appear in the Object Browser.

I hope this is of some use. Please post if something's not clear.

Dan
 
Upvote 0

Forum statistics

Threads
1,214,666
Messages
6,120,806
Members
448,990
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top