PDA

View Full Version : [SOLVED] Mismatch error



Klartigue
08-29-2013, 12:42 PM
Sub EmailFidelity()
Dim oOutlook As Object
Dim oMailItem As Object
Dim oRecipient As Object
Dim oNameSpace As Object
Dim Lastrow As Long
Dim bodyText As String
Dim i As Long

Set oOutlook = CreateObject("Outlook.Application")
Set oNameSpace = oOutlook.GetNameSpace("MAPI")
oNameSpace.Logon , , True


Set oMailItem = oOutlook.CreateItem(0)

With oMailItem

Set oRecipient = .Recipients.Add("FIDELITY FTO IMPORT FOLDER")
oRecipient.Type = 1

.Subject = "test"

.body = "Please see." & vbNewLine & vbNewLine & _
"Let me know if you need anything else." & vbNewLine & vbNewLine & _
"Thanks, " & vbNewLine & vbNewLine & _
"kl " & vbNewLine & _
"kl " & vbNewLine & _
"test" & vbNewLine & vbNewLine & _
"The ."

If Dir(FILE_ATTACH, vbNormal) <> "" Then

.Attachments.Add ("G:\KL\Allocations\FTO CSV UPLOAD\Fidelity Trades.csv")
.Save
End If

End With

End Sub


I have the above code in which I try to email with an attachment. I get an error saying mismatch. I have never emailed with a csv attachement..I am wondering if part of this refers to excel and not csv? If Dir(FILE_ATTACH, vbNormal) <> "" Then

Do you see where the mismatch error could be?

mancubus
08-29-2013, 01:14 PM
If Dir(FILE_ATTACH, vbNormal) <> "" Then

FILE_ATTACH is empty. what is it?

Klartigue
08-29-2013, 01:24 PM
Its saying if there is no file then don't sent the email. But if a file exists, attach it and send the email.

mancubus
08-29-2013, 01:41 PM
so it's a string variable representing the file name to attach.

try this:



Sub EmailFidelity()

Dim oOutlook As Object
Dim oMailItem As Object
Dim oRecipient As Object
Dim oNameSpace As Object
Dim Lastrow As Long
Dim bodyText As String
Dim i As Long
Dim FILE_ATTACH As String

FILE_ATTACH = "G:\KL\Allocations\FTO CSV UPLOAD\Fidelity Trades.csv"

Set oOutlook = CreateObject("Outlook.Application")
Set oNameSpace = oOutlook.GetNameSpace("MAPI")
oNameSpace.Logon , , True

Set oMailItem = oOutlook.CreateItem(0)

With oMailItem
Set oRecipient = .Recipients.Add("FIDELITY FTO IMPORT FOLDER")
oRecipient.Type = 1
.Subject = "test"
.body = "Please see." & vbNewLine & vbNewLine & _
"Let me know if you need anything else." & vbNewLine & vbNewLine & _
"Thanks, " & vbNewLine & vbNewLine & _
"kl " & vbNewLine & _
"kl " & vbNewLine & _
"test" & vbNewLine & vbNewLine & _
"The ."
If Len(Dir(FILE_ATTACH, vbNormal)) > 0 Then
.Attachments.Add FILE_ATTACH
.Save
End If
End With

End Sub

snb
08-29-2013, 02:08 PM
Sub EmailFidelity()
with CreateObject("Outlook.Application").CreateItem(0)
.to = "person@provider.fr"
.Subject = "test"
.body = replace("Please see.~~Let me know if you need anything else.~~"Thanks, ~~kl ~kl ~test~~The ." ,vblf)
.Attachments.Add "G:\KL\Allocations\FTO CSV UPLOAD\Fidelity Trades.csv"
.Send
End With
End Sub

You can also have a look over here:

http://www.snb-vba.eu/VBA_Excelgegevens_mailen_en.html#H6

Klartigue
08-29-2013, 02:14 PM
I figured it out. I had to add:


Const FILE_ATTACH As String = _
"G:\KL\Allocations\FTO CSV UPLOAD\Trades.csv"

snb
08-30-2013, 01:59 AM
I forgot something in the replacement area:

Sub EmailFidelity()
With CreateObject("Outlook.Application").CreateItem(0)
.to = "person@provider.fr"
.Subject = "test"
.body = replace("Please see.~~Let me know if you need anything else.~~Thanks, ~~kl ~kl ~test~~The .","~" ,vblf)
.Attachments.Add "G:\KL\Allocations\FTO CSV UPLOAD\Fidelity Trades.csv"
.Send
End With
End Sub

mancubus
08-30-2013, 02:24 AM
@snb

thanks for the shorter code.

ps: i think, double quote before 'Thanks' should be removed.

snb
08-30-2013, 02:38 AM
Which double quote ?? ;) ;)

mancubus
08-30-2013, 02:50 AM
:thumb
:yes