Open a path that contains msg

aviadht

Board Regular
Joined
Aug 7, 2008
Messages
91
Hi,

Assume tyhat i have an ready mail in some path ("c:\xxxx\yyyy\mymail.msg"). how can i open it with VBA and put my subject in the subject line. the subject should be taken from cell ("a19") and the "to email" should be taken from ("a20").

Thanks,
Aviad
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
I would modify the below to be variable, or to include your message
Code:
  Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim emaila As string
   dim subject as string
 
    subject = thisworkbook.sheets("Sheet1").range("A19").value
    emaila = thisworkbook.sheets("Sheet1").range("A20").value
 
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    strbody = "Text here"
 
    On Error Resume Next
    With OutMail
        .To = emaila
        .CC = ""
        .BCC = ""
        .Subject = subject       
        .body = strbody
        'You can add a file like this
        '.Attachments.Add ("C:\test.txt")
        .Send   
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
 
Upvote 0
Perfect!! now if i want the text to be right to left and not left to right in thebody. Can i do it ?
 
Upvote 0
ok. for this we need HTML so replace the .body with

Code:
.BodyFormat = olFormatRichText
.HTMLbody = strbody

under the strbody = statement put


strbody = "p align=right" & "text here" & "/p"

at the begining of p put < end of right put > then before and after /p put < and >

it wont allow me to show it here coz its code
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,629
Members
452,933
Latest member
patv

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