Test if attachment does not exist, continue if yes. macro

October 8, 2013 at 09:14:16
Specs: Windows 7
Sub SendEmail()
Dim OlApp As New Outlook.Application
Dim myNameSp As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim myExplorer As Outlook.Explorer
Dim NewMail As Outlook.MailItem
Dim OutOpen As Boolean

' Check to see if there's an explorer window open
' If not then open up a new one
OutOpen = True
Set myExplorer = OlApp.ActiveExplorer
If TypeName(myExplorer) = "Nothing" Then
OutOpen = False
Set myNameSp = OlApp.GetNamespace("MAPI")
Set myInbox = myNameSp.GetDefaultFolder(olFolderInbox)
Set myExplorer = myInbox.GetExplorer
End If
' myExplorer.Display
'You don't have to show Outlook to use it

Workbooks.Open FileName:= _

' Sheets("Sheet1").Select

J = 2

GG = 0
Do While GG = 0

J1 = "A" + Trim(Str(J))
J2 = "C" + Trim(Str(J))
J3 = "D" + Trim(Str(J))
j4 = "E" + Trim(Str(J))
PP = ActiveCell.Value
If Trim(PP) = "" Then
GG = 1
bb = "C:\Filter\" + Trim(PP) + ".xlsx"
pp2 = Trim(ActiveCell.Value)

PP3 = Trim(ActiveCell.Value)
pp4 = Trim(ActiveCell.Value)

' Create a new mail message item.
Set NewMail = OlApp.CreateItem(olMailItem)

If Trim(PP3) = "" Then

If Trim(pp2) <> "" Then
With NewMail
.Subject = "E-" + pp4
.To = pp2
.HTMLBody = "Message..

Thank You

Thank you. "
.Attachments.Add (bb)

End With

End If


With NewMail
.Subject = "E-" + pp4
.To = pp2

.HTMLBody = "Message..

Thank You

Thank you. "
.CC = PP3

.Attachments.Add (bb)

End With
End If

End If
J = J + 1


If Not OutOpen Then OlApp.Quit

'Release memory.
Set OlApp = Nothing
Set myNameSp = Nothing
Set myInbox = Nothing
Set myExplorer = Nothing
Set NewMail = Nothing

End Sub

See More: Test if attachment does not exist, continue if yes. macro

October 8, 2013 at 09:37:11

This is the second time that you have posted a macro without any explanation or question. If you want help from the members of this forum, you'll need to put a little more effort into your posts.

I'll repeat my response from the thread you started yesterday:


There are 2 issues with your post:

1 - You posted some code, but you didn't actually ask a question. If you want us to help you, you should try to make it as easy as you can for us to figure out what you are doing and what you want done.

You should post something like...

"The following code is used to (tell us what the code does). What I am trying to do is (tell us what you are having a problem with).

2 - Please click on the blue line at the bottom of this post and read the instructions on how to post VBA code in this fourm. By following the instructions found via that link, the code will be formatted in a manner that will make it much easier for us to read. Of course, that assumes that you used indents when you wrote the code.


You'll need to put a little more effort into your posts before we're going to put any effort into answering them.

Office Forum Moderator

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •
Related Solutions

Ask Question