How to separate text line in Mail Body in VBA

zaska

Well-known Member
Joined
Oct 24, 2010
Messages
1,046
Hi,

Code:
Code:
'Subject string     
MailBody = "enter body text"

I want to add the following Mail Body in the above code but i don't have idea of how to seperate the lines.

The text should be

" Dear Sir,

Please Find the Attached File.
Regards,
Zaska. "
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
First, build your message...

Code:
    Msg = "Dear Sir," & vbNewLine & vbNewLine
    Msg = Msg & "Please find the attached file." & vbNewLine & vbNewLine
    Msg = Msg & "Regards," & vbNewLine
    Msg = Msg & "Zaska"

Then...

Code:
MailItem.Body = Msg
 
Upvote 0
Hi,

Code :
Code:
'Path of stored statements
   Path = "C:\junk\"
 
'Select Row Number of customer to email
  rownum = InputBox("enter customer row number")
 
FileNme = Path & Cells(rownum, 1).Value & ".pdf

In the above code i want to make few modifications

1. Each Client has a Seperate Folder and all the folders of Each client are stored in a single folder " Junk "

2. Instead of the Row Number i want to use the Client Name stored in column A as Default path for Each client

3. I want to attach p.xls and g.xls along with .pdf file.

Could you help me?

Thanks
 
Upvote 0
Hi,

I have assumed the client name in Column A is also the folder name i.e C:\junk\client name\

I have assumed the pdf file is client name.pdf
I have assumed p.xls and g.xls are also in the client folders i.e
C:\junk\client name\p.xls

Code:
Set Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
 
For Each cell In Rng
 
   ClntName = cell.Value
   Path = "C:\junk\" & ClntName & "\"
 
FileNme = Path & ClntName & ".pdf"
FileNmepxls = Path & "p.xls"
FileNmegxls = Path & "g.xls"
 
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
 On Error Resume Next
        With OutMail
            .Subject = EmailSubject
            .To = EmailSendTo
            .Body = "Mail Body"
            .Attachments.Add FileNme
            .Attachments.Add FileNmepxls
            .Attachments.Add FileNmegxls
            .Display
           '.Send
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
 
Next

If you still want to use InputBox to send 1 mail

Code:
rownum = InputBox("enter customer row number")
ClntName = Cells(rownum, 1).Value
Path = "C:\junk\" & ClntName & "\"
 
FileNme = Path & ClntName & ".pdf"
FileNmepxls = Path & "p.xls"
FileNmegxls = Path & "g.xls"
 
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.Subject = EmailSubject
.To = EmailSendTo
.Body = "Mail Body"
.Attachments.Add FileNme
.Attachments.Add FileNmepxls
.Attachments.Add FileNmegxls
.Display
'.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
 
Last edited:
Upvote 0
Sir,

Is it possible to extract the E-mail address of each client from outlook 2010 ( Inbox and Outbox ) and store them in Column A in Junk Folder?

I thank you very much for the above code

Have a nice day
 
Upvote 0

Forum statistics

Threads
1,214,573
Messages
6,120,318
Members
448,956
Latest member
Adamsxl

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