Generating an Email with VBS ?

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
788
Office Version
  1. 365
Platform
  1. Windows
Hi,
i know VBS works almost exactly like VBA so this should be doable:

i have the following which currently works:

Code:
Dim outobj, mailobj
          Dim strFileText
          Dim objFileToRead


Name1 = Inputbox("Enter Name")
Code1 = Inputbox("Enter your Code")


          Set outobj = CreateObject("Outlook.Application")
          Set mailobj = outobj.CreateItem(0)


            With mailobj
	    .to = "testto@mail.com"
            .cc = "testcc@mail.com"
            .Subject = "Test"
            .Body = "Hi," & vbCrLf & vbCrLf & _
"Name:" & " " & Name1 & vbCrLf & _
"Code:" & " " & Code1 & vbCrLf & vbCrLf & _
"Best Regards,"


.Display
          End With


          'Clear the memory
          Set outobj = Nothing
          Set mailobj = Nothing

Though im wanting to include the default signature, exactly how it would it outlook
Also would like to bold the Name1 and Code1 parts of the body, is it possible?

Any help appreciated
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
You can use HTML code to achieve the desired result. First, build a string that contains the HTML code...

HTML:
Dim strHTML As String

strHTML = "<p>Hi,</p>" & _
    "<p>Name: <b>" & Name1 & "</b><br>" & _
    "Code: <b>" & Code1 & "</b></p>" & _
    "<p>Best Regards,</p>"

Then assign the HTML string to the .HTMLBody property of the MailItem object...

Code:
.htmlbody = strHTML

To add a signature, have a look at the following link...

https://www.rondebruin.nl/win/s1/outlook/signature.htm

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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