PDA

View Full Version : [SOLVED:] Help for each attach



startuga
01-08-2014, 02:20 AM
Hi guys,
I facing some problems, cuz im trying to attach image in task email, for doing that im using this code:


Private Sub CommandButton5_Click()
Shell "wscript C:\Users\udj003\Desktop\mspaint.vbs"
myattach = "c:\temp\img_attach.png"
End Sub




Private Sub CommandButton3_Click()
NUser = Application.GetNamespace("MAPI").CurrentUser
FirstName = Right(NUser, Len(NUser) - 1 - InStr(1, NUser, ",", vbTextCompare))
LastName = Left(NUser, InStr(1, NUser, ",", vbTextCompare) - 1)
Dim strBody As String
Dim objOut As Outlook.Application
Dim objTask As Outlook.TaskItem
Dim blnCrt As Boolean

Set objoutlook = CreateObject("Outlook.Application")
Set objMail = objoutlook.CreateItem(0)
strBody = " Informações de utilizador e computador" & vbNewLine & vbNewLine & _
"Utilizador:" & FirstName & " " & LastName & (TextBox4.Text) & vbNewLine & _
"Departamento: " & (TextBox6.Text) & vbNewLine & _
"Computador: " & (TextBox7.Text) & vbNewLine & _
"Sistema Operativo: " & (TextBox10.Text) & vbNewLine & vbNewLine & vbNewLine & _
"Prioridade da Situação: " & (ComboBox5.Value) & " " & "Tipo de Equipamento: " & (ComboBox6.Value) & " " & "Categoria: " & (ComboBox1.Value) & " " & "Tipo de Intervenção Necessária: " & (ComboBox3.Value) & vbNewLine & vbNewLine & vbNewLine & _
"Descrição do Problema:" & vbNewLine & vbNewLine & (TextBox11) & vbNewLine & vbNewLine & vbNewLine


On Error Resume Next
Select Case True
Case ComboBox5.Value = "Baixa"
On Error GoTo CreateOutlook
Set objOut = GetObject(, "Outlook.Application")
CreateItem:
On Error GoTo 0
Set objTask = objOut.CreateItem(olTaskItem)
With objTask
.Assign
.Importance = olImportanceLow
.subject = "Help Desk"
.body = strBody
.Mileage = FirstName & " " & LastName & " " & "(" & (TextBox4.Text) & ")"
.BillingInformation = TextBox6.Text
.Companies = ComboBox1.Value
On Error Resume Next
.Attachments.Add (filepath)
On Error Resume Next
.Attachments.Add (myattach)
.Recipients.Add ("EMAIL")
.Send
End With
End
If blnCrt = True Then objOut.Quit
Set objTask = Nothing
Set objOut = Nothing
Exit Sub
End
CreateOutlook:
Set objOut = CreateObject("Outlook.Application")
blnCrt = True
Resume CreateItem
End
End



The problem is, i need to attach more than one image, to do that, i need to implement a for each, but i have no ideia how can i do that.

westconn1
01-10-2014, 05:15 AM
i need to implement a for each,for each what?
do you have a list of files you want to attach?
do you want to attach all files in some folder?
are filepath and myattch dimensioned and assigned values elsewhere?
are they single files or arrays?


Set objoutlook = CreateObject("Outlook.Application")
Set objMail = objoutlook.CreateItem(0)
here you set an application and mailitem, to undefined variables, but never use in your code