If Or Statement Assistance

Worsty

Board Regular
Joined
Jun 29, 2004
Messages
183
I have the following code:

Set MyOutlook = New Outlook.Application
Set MyMail = MyOutlook.CreateItem(olMailItem)

MyMail.To = "myname@myco.com"
MyMail.CC = ""
MyMail.BCC = Text1
MyMail.BodyFormat = olFormatHTML

MyMail.Subject = "Monthly Newsletter"
MyBodyText = "Here is the document"
Set myattachments = MyMail.Attachments
myattachments.Add "C:\JetComp.doc"
MyMail.SentOnBehalfOfName = "MyMailBox"

What I'd like it to do is to look at a combo box (combo16) and if the value is Ben, then my attachment should be BensAttachment, but if it combo box value is David, then my attachment should be DavidsAttachment, and so on.

Can someone help me out here please? Thanks in advance -- You guys are great!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I suppose I should give you all the code. Sorry about that.

Private Sub Command4_Click()
On Error GoTo Err_Command5_Click
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem

Dim MyBodyText As String
Dim frm As Form
Dim ctl As Control
Dim varItem As Variant
Dim strSql As String
Dim myattachments As Variant
Dim lItemCount As Long
Dim mailStationery As String

'send email with spreadsheet

Set MyOutlook = New Outlook.Application
Set MyMail = MyOutlook.CreateItem(olMailItem)



MyMail.To = "jwsullivan@gaic.com"
MyMail.CC = ""
MyMail.BCC = Text1
MyMail.BodyFormat = olFormatHTML

MyMail.Subject = "Monthly Newsletter"
MyBodyText = "Here is the document"
Set myattachments = MyMail.Attachments
myattachments.Add "C:\JetComp.doc"
MyMail.SentOnBehalfOfName = "Great American SHS NonProfit"

'******************************************************
'put the HTML code for the stationery to a variable and then assign
'it to the HTMLBody
If Combo16.Value = "Newsletter" Then
mailStationery = "<HTML><HEAD><TITLE></TITLE>"
mailStationery = mailStationery & "<META http-equiv=Content-Type content='text/html; charset=windows-1252'>"
mailStationery = mailStationery & "</HEAD><BODY leftMargin=0 topMargin=0 marginheight=0 marginwidth=0>"
mailStationery = mailStationery & "<TABLE cellSpacing=0 cellPadding=0 width=612 border=0>"
mailStationery = mailStationery & "<TBODY><TR><TD vAlign=top align=left width=612 colSpan=2 height=118>
top.jpg
</TD></TR>"
mailStationery = mailStationery & "<TR><TD vAlign=top align=left width=28>
blue_bar.jpg
</TD><TD vAlign=top align=left width=584></TD></TR>"
mailStationery = mailStationery & "<TR><TD vAlign=top align=middle colSpan=2 height=125 border='0'>
gai_logo.jpg
</TD></TR></TBODY></TABLE></BODY></HTML>"


Else
mailStationery = ""
End If
'******************************************************
MyMail.HTMLBody = mailStationery
'MyMail.HTMLBody = "<HTML><HEAD>My HTML Background</HEAD>" & _
"<BODY bgcolor=Green></BODY></HTML>"

MyMail.Display

Set MyMail = Nothing
Set myattachments = Nothing
Set MyOutlook = Nothing
Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

End Sub
 
Upvote 0

Forum statistics

Threads
1,216,222
Messages
6,129,586
Members
449,520
Latest member
TBFrieds

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