Below is my current coding in my module that sends emails via Outlook but we are switching to gmail. I tried updating to Gmail but it was still looking for outlook and not google/gmail.
Option Compare Database
Public strRptFilter As String
Public blnRepIDHasData As Boolean
Public Function IsOutlookOpen() As Boolean
On Error Resume Next
IsOutlookOpen = True
Set oOutlook = GetObject(, "Outlook.Application")
If oOutlook Is Nothing Then
IsOutlookOpen = False
End If
End Function
Function Email_Via_Outlook(varAddress, varSubject, varBody, varCC, DisplayMsg As Boolean, blnDoNotCC As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
On Error GoTo errorHandler
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(varAddress)
objOutlookRecip.Type = olTo
.Subject = varSubject
.Body = varBody
'If NoCC is checked, bypass the addition of the cc addresses.
If blnDoNotCC = False Then
.CC = varCC
End If
' Add attachments to the message.
If Not IsMissing(AttachmentPath) And AttachmentPath <> "" Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
Exit Function
errorHandler:
errNameFrom = "Email_Via_Outlook"
MsgBox "Error occured at " & errNameFrom & ": " & Err.Number & "-" & Err.Description
End Function
Function CheckName(fileName As String) As String
Dim pos As Long
pos = InStrRev(fileName, ".")
If (pos > 0) Then
fileName = Left$(fileName, pos - 1)
End If
CheckName = fileName & ".xlsx"
End Function