VBA sending emails

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,113
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I want to send an email through vba in using an Outlook template.

The code that I have references a drive pathway:

VBA Code:
    Dim FileExtStr As String

    Dim FileFormatNum As Long

    Dim Sourcewb As Workbook

    Dim Destwb As Workbook

    Dim TempFilePath As String

    Dim TempFileName As String

    Dim OutApp As Object

    Dim OutMail As Object

    Dim varMyAttachment As Variant


    Set OutApp = CreateObject("Outlook.Application")

    Set OutMail = OutApp.CreateItemFromTemplate("C:\Folder1\Folder2\Folder3\Folder4\Folder5\Folder6\Titled.msg")   'Change path to object.
                   
 'getParentFolder(ThisWorkbook.Path) & "\" & Worksheets(1).Range("A39").Text 
   
    With OutMail

        '.To = ""

        '.CC = ""

        '.BCC = ""
        
    '.Subject = ""


I would like to provide Set OutMail to Thisworkbook.Path as referenced as in the following proposed example.

For example;

VBA Code:
 Set OutMail = OutApp.CreateItemFromTemplate(getParentFolder(ThisWorkbook.Path) & "\" & Worksheets(1).Range("A39").Text")   'Change path to object.

Can someone help me?

Thank you!
pinaceous
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
So where is your problem, you seem to have everything there.

DO you need a GetParentFolder function?
VBA Code:
Function getParentFolder(ByVal strFolder As String)
  Dim strSlash As String
  
  If strFolder Like "*\*" Then
    strSlash = "\"
  Else
    strSlash = "/"
  End If
  
  getParentFolder = Left(strFolder, InStrRev(strFolder, strSlash) - 1)
End Function
 
Upvote 0

Forum statistics

Threads
1,215,374
Messages
6,124,571
Members
449,173
Latest member
Kon123

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