Home > Mobile >  Is it possible to have an excel macro open outlook in browser and populate the fields of a new messa
Is it possible to have an excel macro open outlook in browser and populate the fields of a new messa

Time:07-27

Question: Is it possible to create a macro that opens outlook in a web browser and populates the fields of a new message as well as attach a file? The outlook portion of the current macro only opens outlook in a browser.

ActiveWorkbook.FollowHyperlink Address:="https://outlook.office365.com/mail/**shared mailbox address**"

Background: I am trying to update an excel macro that currently saves a pdf of the sheet, opens the outlook application, fills out the necessary fields and attaches the saved pdf to the email. This macro has worked fine, but we have recently moved to using a shared mailbox to send the message. Now the users have encountered problems sending from the shared mailbox using the outlook application. The solution is to use outlook in the browser (edge), but the macro I currently have can only open outlook in the browser and requires the user to fill out all the fields and find and attach the saved pdf. There have been problems with this and I was hoping there was a way to automate the process like our old macro would.

Old macro:

    Set OlApp = CreateObject("Outlook.Application")
    Set NewMail = OlApp.CreateItem(0)
    
    On Error Resume Next
    With NewMail
        .To = ReportName
        .CC = ""
        .Subject = TempFileName
        .Body = ""
        .Attachments.Add FileFullPath '--- full path of the pdf where it is saved
        .Display   '.Send or use .Display to show you the email before sending it.
    End With
    On Error GoTo 0

CodePudding user response:

Well, Yes and No. Yes, you can get VBA to do this... but No, it won't be remotely as easy as running it through the desktop application.

A workaround that still uses desktop application, is to

  1. Give all users that need to send the email access to this inbox from their own desktop apps.
  2. Use the ".SendUsingAccount" property
Sub ExampleSub()
    
    Dim OLApp As Object
    Dim NewMail As Object

    Set OLApp = CreateObject("Outlook.Application")
    Set NewMail = OLApp.CreateItem(0)
    
    On Error Resume Next
    With NewMail
        .SentOnBehalfOfName = "[email protected]"
        .To = "[email protected]"
        .CC = ""
        .Subject = "Example Subject"
        .Body = "Good Morning..."
        '.Attachments.Add FileFullPath '--- full path of the pdf where it is saved
        .Display   '.Send or use .Display to show you the email before sending it.
    End With
    On Error GoTo 0

End Sub
  • Related