Link to home
Start Free TrialLog in
Avatar of Josh House
Josh HouseFlag for United States of America

asked on

Automating an Excel Template using VBA and Outlook

I have two columns that I am trying to reference to spit out multiple values for the possible outcome of two separate input values. For Example:
A         B                   C
SCAC      Linear Feet         Weight
PITD              20                  10000
ESTE              10                  15000
SAIA              25                  20000
ABFS             20                  25000

Input Values

Linear Feet     Weight
20                     20000

If the entered field is greater than or equal to I want it to return all values that match the criteria
Sorry guys, I just word from my boss who wants the INPUT values to be either/or a match for LINEAR FEET or WEIGHT...any ideas to accommodate this new ask?


What's the best way to write this formula?

      I am trying to build a formula that reference cells in a table. My goal is to only return values that have data in the reference cells. So if a cell in the table is blank don't return it. Also it is not referencing the first row in my table. Any ideas on how to fix?

=IFERROR(INDEX('Carrier Rules and Contact Info'!$A$A,SMALL(IF(('Volume Template'!$B$4>='Carrier Rules and Contact Info'!$B:$B)+('Volume Template'!$C$4>='Carrier Rules and Contact Info'!$C:$C),ROW('Carrier Rules and Contact Info'!$B:$B)),ROW('Carrier Rules and Contact Info'!2:2))),"")

Open in new window

How can I improve this formula?

Add Checkboxes that will return emails addresses in the BCC field into Outlook
In desperate need of help

I am building an email in Excel for Outlook using the following code:

I want to use check boxes (using the form controls) to decide whether an email is used.

If the check box reference cell is true input the value of a cell (an email address) into the BCC field.

If Cell H4=True return Cell F4.

Going down a list of about 30 entries so this needs to loop until there are no more check boxes

Sub Mail_Selection_Range_Outlook_Body()
'Don't forget to copy the function RangetoHTML in the module.
'Working in Excel 2000-2016
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

Set rng = Nothing
On Error Resume Next
'Only the visible cells in the selection
'Set rng = Selection.SpecialCells(xlCellTypeVisible)
'You can also use a fixed range if you want
Set rng = Sheets("Volume Template").Range("K4:L14").SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.EnableEvents = False
.ScreenUpdating = False
End With

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC =
.HTMLBody = RangetoHTML(rng)
.Display 'or use .Send
End With
On Error GoTo 0

With Application
.EnableEvents = True
.ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Function RangetoHTML(rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook

TempFile = Environ$("temp") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

'Copy the range and create a new workbook to past the data in
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
On Error GoTo 0
End With

'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
.Publish (True)
End With

'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")

'Close TempWB
TempWB.Close savechanges:=False

'Delete the htm file we used in this function
Kill TempFile

Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function

Open in new window

How do I adjust the code below to accomplish this task? I am very new and still learning.
Avatar of Shums Faruk
Shums Faruk
Flag of India image

I believe this question needs to split. 1 for Excel formula and one for Outlook VBA.
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Josh House


I will split this up into 2 questions sorry for any confusion this may have caused
Does Excel Formula helped you?

If Yes, I would request you to close this question and raise another one for Outlook VBA.
Yes, that worked perfectly I will close this question
this helped tremendously Thank you
You're Welcome Josh! Glad I was able to help.
I added the new question as Add Checkboxes that will return emails addresses in the BCC field into Outlook