Generating an Email with VBS ?
Results 1 to 4 of 4

Thread: Generating an Email with VBS ?

  1. #1
    Board Regular
    Join Date
    Nov 2016
    Posts
    585
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Generating an Email with VBS ?

    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

  2. #2
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,798
    Post Thanks / Like
    Mentioned
    34 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Generating an Email with VBS ?

    You can use HTML code to achieve the desired result. First, build a string that contains the HTML code...

    HTML Code:
    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 by Domenic; Jun 19th, 2019 at 03:38 PM.

  3. #3
    Board Regular
    Join Date
    Nov 2016
    Posts
    585
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Generating an Email with VBS ?

    @Domenic thankyou, got it working

  4. #4
    MrExcel MVP
    Join Date
    Mar 2004
    Location
    Canada
    Posts
    18,798
    Post Thanks / Like
    Mentioned
    34 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Generating an Email with VBS ?

    You're very welcome!

    Cheers!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •