Macro to email Report

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have the following macro below, but need the msxbox to show the text in Blue and in bold

It would be appreciated if someone could amend my code to accomodate this request


Code:
 Sub Email_Creditors_Report()

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 strBody As String

Dim LR As Long

Dim sumTotal As Double

Dim ws As Worksheet

Dim FileExtStr As String

Dim FileFormatNum As Long

Dim NamesRange As Range

Dim NameCell As Range

Dim NamesList As String



On Error GoTo Cleanup



' Disable screen updating and events

Application.ScreenUpdating = False

Application.EnableEvents = False



Set Sourcewb = ThisWorkbook

Set ws = Sourcewb.Sheets("BR1)



' Store the sum of the range K2:KLR in sumTotal

With ws

LR = .Cells(.Rows.Count, "K").End(xlUp).Row

sumTotal = Application.WorksheetFunction.Sum(.Range("K2:K" & LR))

End With



' Check total

If sumTotal < 10 Then



ShowBoldBlueMessageBox

ShowNoCreditorsMessageBox

GoTo Cleanup

End If



' Copy the worksheet to a new workbook

ws.Copy

Set Destwb = ActiveWorkbook



' Change all cells in the worksheet to values

With Destwb.Sheets(1).UsedRange

.Value = .Value

End With



' Save the new workbook, prepare email

TempFilePath = Environ("TEMP") & "\"

TempFileName = Destwb.Sheets(1).Name & "-Creditors " & Format(Now, "dd-mmm-yy h-mm-ss")



' Define file extension and format

FileExtStr = ".xlsx"

FileFormatNum = 51



' Save the new workbook

Destwb.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum



' Create Outlook objects

Set OutApp = CreateObject("Outlook.Application")

Set OutMail = OutApp.CreateItem(0)



' Prepare email body

Set NamesRange = ws.Range("S1:S5")

For Each NameCell In NamesRange

If Len(NameCell.Value) > 0 Then

NamesList = NamesList & NameCell.Value & ", "

End If

Next NameCell



If Len(NamesList) > 0 Then

NamesList = Left(NamesList, Len(NamesList) - 2) ' Remove the last comma and space

End If



strBody = "Hi " & NamesList & vbNewLine & vbNewLine

strBody = strBody & "Attached Please find Creditors Report. Please attend to those that are 90 days and over" & vbNewLine & vbNewLine

strBody = strBody & "Where you have creditors that are 90 days and over, please provide feedback" & vbNewLine & vbNewLine

strBody = strBody & "Where there are credit balances on the ageing, these must be addressed and allocated as this distorts the ageing" & vbNewLine & vbNewLine

strBody = strBody & "Regards" & vbNewLine & vbNewLine

strBody = strBody & "Howard"



' Create and display/send the email

With OutMail

.To = Join(Application.WorksheetFunction.Transpose(ws.Range("T1:T5").Value), ";")

.CC = ""

.BCC = ""

.Subject = "Creditors Report - " & Format(Now, "dd-mmm-yy h-mm-ss")

.Body = strBody

.Attachments.Add TempFilePath & TempFileName & FileExtStr

.Display ' Use .Send to send automatically or .Display to check email before sending

End With



' Close and delete the temporary workbook

Destwb.Close SaveChanges:=False

Kill TempFilePath & TempFileName & FileExtStr



Cleanup:

' Release Outlook objects

On Error Resume Next

Set OutMail = Nothing

Set OutApp = Nothing



' Enable screen updating and events

Application.ScreenUpdating = True

Application.EnableEvents = True



If Err.Number <> 0 Then

MsgBox "An error occurred: " & Err.Description, vbExclamation

End If

End Sub

    Sub ShowNoCreditorsMessageBox()
    MsgBox "There are no Creditors 90 Days over, therefore an email will not be generated.", vbInformation + vbOKOnly, "No Creditors Found
     End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I don't think that you can change those features in the text of a message box. The only way I can think of doing that, is to create a userform with the text in a "Label". Then you can change the Forecolor to blue and font to Bold. Replace the "MsgBox" line of code with code to open the userform. You would also need a commandbutton on the userform to close it.
 
Upvote 0
I thought that it cannot be done, except using a label via the userform.

Going to try this
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

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