- Joined
- Jun 18, 2005
- Messages
- 1
- Reaction score
- 0
hi every one; i need help in this problem.
i wrote a vba code in outlook inorder to automate sending an email with attachment, but the problem is that the attachment is not refreshing.
the programm calls a batch file in order to prepare a constant zip file and then create a mailitem and add the address and subject and then add the attachment. the result is that always the attachment is the one sent before. what i mean is that if i sent an email with the attachment name x and size 20K then reorder the send Procedure the file will be the same size while the prepared one by winzip is change lets say 10K.
the attachment changes to the correct size after sending for 2 or three times.
note i'm using outlook 2003.
you'll find below the code i wrote. Please help me in this problem.
On Error Resume Next
Dim x As Variant
x = Shell("c:\windows\system32\cmd.exe /k c:\exp.bat", vbNormalFocus)
Dim myolapp As Object
Set myolapp = CreateObject("outlook.Application")
Dim mymail As Outlook.MailItem
Set mymail = myolapp.CreateItem(olMailItem)
mymail.Save
Dim myattach As Outlook.Attachments
Set myattach = mymail.Attachments
While myattach.Count > 0
myattach.Remove Count ' i added this line to check if oulook saving the attachment.
Wend
With mymail
.To = "(e-mail address removed)"
.Subject = "export data"
End With
myattach.Add "C:\zipfile.ZIP", olByValue, 2, "ZIPPING"
mymail.Send
mymail.Close (olSave)
mymail = Nothing
myolapp = Nothing
i wrote a vba code in outlook inorder to automate sending an email with attachment, but the problem is that the attachment is not refreshing.
the programm calls a batch file in order to prepare a constant zip file and then create a mailitem and add the address and subject and then add the attachment. the result is that always the attachment is the one sent before. what i mean is that if i sent an email with the attachment name x and size 20K then reorder the send Procedure the file will be the same size while the prepared one by winzip is change lets say 10K.
the attachment changes to the correct size after sending for 2 or three times.
note i'm using outlook 2003.
you'll find below the code i wrote. Please help me in this problem.
On Error Resume Next
Dim x As Variant
x = Shell("c:\windows\system32\cmd.exe /k c:\exp.bat", vbNormalFocus)
Dim myolapp As Object
Set myolapp = CreateObject("outlook.Application")
Dim mymail As Outlook.MailItem
Set mymail = myolapp.CreateItem(olMailItem)
mymail.Save
Dim myattach As Outlook.Attachments
Set myattach = mymail.Attachments
While myattach.Count > 0
myattach.Remove Count ' i added this line to check if oulook saving the attachment.
Wend
With mymail
.To = "(e-mail address removed)"
.Subject = "export data"
End With
myattach.Add "C:\zipfile.ZIP", olByValue, 2, "ZIPPING"
mymail.Send
mymail.Close (olSave)
mymail = Nothing
myolapp = Nothing