VBA sending emails

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,124
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 the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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