Excel VBA to Outlook Email Draft - How to save email draft copy to sharepoint / How to use template from sharepoint?

elitef

Board Regular
Joined
Feb 3, 2016
Messages
58
Hi Everyone,

Hoping for some assistance from the smart folks on here.

I have a VBA in excel which generates an Outlook message draft from a template.
I'd like to know, if at all possible, two things:
- How can I make it so that the draft, once opened, is saved as a file to a sharepoint location?
-- If not possible to do that, then is there a way to have the VBA convert the email draft to a .doc/.docx document and upload that instead?
- How can I have the script use a template which is located on a sharepoint as opposed to locally on a desktop?

If neither is possible, does anyone have any workarounds to get this to somewhat work?

Any help would be greatly appreciated.

VBA Code:
Dim OO As Object
On Error Resume Next
Set OO = GetObject(, "Outlook.Application")
On Error GoTo 0
If OO Is Nothing Then
ans = MsgBox("Outlook is not currently open. Would you like to open Outlook now?     If yes, Outlook will open and you will have to click on the Send Comms button again.", vbYesNo)
If ans = vbYes Then Shell ("Outlook")
If ans = vbNo Then Exit Sub
Else

    ThisWorkbook.Sheets("Email").Range("A" & ThisWorkbook.Sheets("Email").Rows.Count).End(xlUp).Offset(0).Range("K1").Value = Format(Now(), "MM/DD/YYYY hh:mm:ss")
 
    Dim NewEmail As MailItem
    Dim PathFileName As String
 

    Dim Recp As Variant
    Dim I As Long
    For I = 0 To Worksheets("List").Range("L" & Rows.Count).End(xlUp).Row Step 400
    Recp = Worksheets("List").Range("L2").Offset(I).Resize(400)
 
  PathFileName = Application.ActiveWorkbook.Path & "\Templates\EMAIL.oft"    'This is the section I'd love to see if at all possible to use a template off of a sharepoint site instead of locally
  Set NewEmail = CreateItemFromTemplate(PathFileName)
 

  With NewEmail

    .Subject = Worksheets("Email").Range("H1").Value
 
    .HTMLBody = Replace(.HTMLBody, "#BODY", Worksheets("Email").Range("H6").Value)
 
 
    BodyWithoutSignature = .HTMLBody
    .SentOnBehalfOfName = "Secondary@mailbox.com"
    .DeferredDeliveryTime = DateAdd("n", 3, Now)
    .ReplyRecipients.Add "AdditionalDL@mailbox.com"

    .To = "AdditionalDL@mailbox.com"
    .BCC = Join(Application.Transpose(Recp), ";")
    .Display
    .HTMLBody = BodyWithoutSignature

 
  End With
  Next
   
  End If
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,224,802
Messages
6,181,054
Members
453,014
Latest member
Chris258

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