troubleshooting Question

Automating an Excel Template using VBA and Outlook

Avatar of Josh House
Josh HouseFlag for United States of America asked on
OutlookVBAMicrosoft Excel
8 Comments1 Solution190 ViewsLast Modified:
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))),"")

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

How do I adjust the code below to accomplish this task? I am very new and still learning.
Excel VBA Developer
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros