attachments to email in windows form

ccbltd need help

New member
Joined
Mar 25, 2009
Messages
4
Programming Experience
Beginner
hi

I am trying to use the following code to automate an email to be sent out to prechosen fields, the email part works just fine but i can not get the attachment to work can any one see the errors in my ways.

Dim Answer As Object
Dim FileToAttach As Object
Dim Msg As String
Dim MyApp As Boolean
Dim olapp As Object
Dim olEmail As Object
Dim SendTo As String
Dim Subj As String
Dim InsertSig As String
'Outlook constants aren't available using late binding
Const olByValue = 1
Const olMailItem = 0

'Setup email variables using worksheet cells F8, K8, B40 AND B41
SendTo = Globals.Sheet1.Cells(8, "F").Text 'F8
Subj = Globals.Sheet1.Cells(8, "K").Text 'K8
Msg = "Dear," & Globals.Sheet1.Cells(41, "B").Text

FileToAttach = MailItem.Attachments.add(FileFilter:="*.pdf", Title:="C:\Documents and Settings\David.Curcic\Desktop\Copy of ccb quote calculators\calculator\telecomsproposal.pdf")
On Error Resume Next
olapp = GetObject(, "Outlook.Application")

olapp.Session.Logon()

'Create an Outlook Mail Item
olEmail = olapp.CreateItem(olMailItem)

On Error Resume Next
With olEmail
.To = SendTo
.Subject = Subj
.Body = Msg
.Attachments.Add(FileToAttach, olByValue)
.Send()
End With



olapp.Session.logoff()
If MyApp Then olapp.Quit()

'Release Objects
olapp = Nothing
olEmail = Nothing
thanks in advance

Regards

Dave
 
Back
Top