Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9159089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:24:31+00:00 2026-06-17T13:24:31+00:00

I am writing a macro to send an e-mail from an excel sheet. The

  • 0

I am writing a macro to send an e-mail from an excel sheet. The macro prepares a few reports and then has a function to prepare the e-mail for the report. Everything works fine except when it gets to the .Send line it gives me a run time error -2147467259. Not sure what this means, but would appreciate the help.

Here is the code for the function:

Function Mail_Reports(ByRef wkDate2 As String, fileDate2 As String, wkNumber2 As String, thisYear2 As String)
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, Outlook 2010.
' This example sends the last saved version of the Activeworkbook object .
    Dim OutApp As Object
    Dim OutMail As Object
    Dim mailList As String
    Dim i As Long, lstRow As Long, p As Long, addressNum As Long, begRow As Long
    Dim proNam2 As String
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    'On Error Resume Next
   ' Change the mail address and subject in the macro before you run it.
    For i = 1 To 5 Step 1
        mailList = ""
        lstRow = Sheets("Data").Cells(Rows.Count, i).End(xlUp).Row
        addressNum = lstRow - 16
        begRow = lstRow - addressNum
        proNam2 = Sheets("Data").Cells(16, i)
        proNam2 = Replace(proNam2, " ", "")
        For p = 1 To addressNum Step 1
            mailList = Sheets("Data").Cells(begRow + p, i) & " ; " & mailList
        Next p
        With OutMail
            .To = mailList
            '.CC = "" remove comma and use this if you want to cc anyone, can be string or variable
            '.BCC = "" remove comma and use this if you want to cc anyone, can be string or variable
            .Subject = "Test"
            .HTMLBody = "<HTML><BODY><Font Face=Calibri(Body)><p>Hi All,</p><p2>Attached to this e-mail is the test file.<p2/><br><br><p3>Best,<p3/></font></BODY></HTML>"
            .attachments.Remove 1
            .attachments.Add "C:\Documents and Settings\test.xlsx"
            .Display
            .Send
    Next i


    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:24:32+00:00Added an answer on June 17, 2026 at 1:24 pm

    Can you please try with just,

    1. Save the report file into a local drive
    2. use one email address first, so remove the for loop
    3. send it with just one file/range/workbook.
    4. remove html tags for signature or etc..

    Code:

    With WB '-- workbook
            .SaveAs TempFilePath & TempFileName & FileExtStr, _
                    FileFormat:=FileFormatNum
            On Error Resume Next
            With OutMail
                .To = "myname@myname.com"
                .CC = ""
                .BCC = ""
                .Subject = "This is the Subject line"
                .Body = "Here is a Report on My VBA analysis"
                .Attachments.Add Dest.FullName
                'You can add other files also like this
                '.Attachments.Add ("C:\testmail.txt") '-- .xls
                .Send   'or use .Display
            End With
            On Error GoTo 0
            .Close SaveChanges:=False
        End With
    
    • Update based on the comments with OP:

    Looking at your email concat loop, you do not have to do it each time when a new book comes UNLESS YOUR MAILING LIST DIFFERS FOR EACH WORKBOOK…. You may take that loop out of the mail workbooks iteration.

    For p = 1 To addressNum Step 1
        mailList = Sheets("Data").Cells(begRow + p, i) & " ; " & mailList
    Next p
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a VBA macro in Excel that analyzes data from the spreadsheet and
I am writing a macro in Excel where I need to get a substring
I'm writing an Excel macro , and I'm having trouble clearing a Scripting.Dictionary object
I am writing a macro in Excel and I am trying to save a
I am writing a macro in VBA for excel in which I would like
I am writing a macro where there is a central input sheet - let
Summary: I am writing a macro that takes names from many different sheets in
I am writing a macro and I need to disable the save function on
I am writing a macro script in 3 steps: read an excel file by
I am writing a Macro in excel VBA that creates a data validation list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.