2014-10-03 12 views
6

VBA ve görünüm üzerinden çoklu ekleri olan bir e-posta göndermeye çalışıyorum.E-posta veya tüm dizin (VBA) içinde göndermek için birden fazla dosya eklemek V123 ve diğer güvenlik açılarıyla (VBA)

Bir eke/dosyaya yol belirlediğimde ve birden çok ek ekleyebiliyorsam, çalıştığım kod da tam olarak ne olduklarını bildiğim halde ileriye hareket etmeyeceğim - dosya adları kadar farklı sayımlar da olacak .

Aşağıdaki örnekte gösterildiği gibi joker karakterleri kullanarak göndermek isterim ancak sanırım bir dizine işaret eden bir çeşit döngü kullanmam gerekecek.

Çözüme bir tonluk baktım ama henüz özel durumumla çalışan bir şey görmedim.

 Private Sub Command22_Click() 
     Dim mess_body As String 
     Dim appOutLook As Outlook.Application 
     Dim MailOutLook As Outlook.MailItem 
     Set appOutLook = CreateObject("Outlook.Application") 
     Set MailOutLook = appOutLook.CreateItem(olMailItem) 

      Set appOutLook = CreateObject("Outlook.Application") 
      Set MailOutLook = appOutLook.CreateItem(olMailItem) 
      With MailOutLook 
      .BodyFormat = olFormatRichText 
      .To = "[email protected]" 
      .Subject = "test" 
      .HTMLBody = "test" 
      .Attachments.Add ("H:\test\Adj*.pdf") 
      '.DeleteAfterSubmit = True 
      .Send 
      End With 
      MsgBox "Reports have been sent", vbOKOnly 
     End Sub 
+0

kullanın [DIR] (http://stackoverflow.com/questions/10380312/loop-through-files-in-a-folder-using-vba/10382861#10382861) –

+0

için teşekkür ederiz cevabın. .Attachments.Add Dir ("H: \ test \") denedim ve "Bu dosyayı bulamıyorum. Yolu ve dosya adını doğrulayın" diyerek bir hata aldım. – gfuller40

cevap

11

Denediğin şey bu mu? (Denenmemiş)

Private Sub Command22_Click() 
    Dim mess_body As String, StrFile As String, StrPath As String 
    Dim appOutLook As Outlook.Application 
    Dim MailOutLook As Outlook.MailItem 

    Set appOutLook = CreateObject("Outlook.Application") 
    Set MailOutLook = appOutLook.CreateItem(olMailItem) 

    '~~> Change path here 
    StrPath = "H:\test\" 

    With MailOutLook 
     .BodyFormat = olFormatRichText 
     .To = "[email protected]" 
     .Subject = "test" 
     .HTMLBody = "test" 

     '~~> *.* for all files 
     StrFile = Dir(StrPath & "*.*") 

     Do While Len(StrFile) > 0 
      .Attachments.Add StrPath & StrFile 
      StrFile = Dir 
     Loop 

     '.DeleteAfterSubmit = True 
     .Send 
    End With 

    MsgBox "Reports have been sent", vbOKOnly 
End Sub 
+0

@Downvoter: Reddetmeyi açıklamak ister misiniz? –

+0

+1 Hmm, neden bu reddedildi? –