【问题标题】:.attachment issues in vba.vba 中的附件问题
【发布时间】:2021-06-09 09:38:11
【问题描述】:
   Dim strto As String
   Dim lastrow As Long
   stirfile = Dir(DestPath & "*.pdf*")
   For i = lastrow To 7 Step 1
   lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
   strto = Range("G7") & ";" & Range("K7") & ";" & Range("O7") & ";" & Range("S7")
   With Mail
      .Subject = "Quote reg for VAM project"
      .From = "arunkumarg@gmail.com"
      .To = strto
      .CC = ""
      .BCC = ""
      .TextBody = strbody
              .Attachments.Add (DestPath)
   End With
   Next i
   Mail.Send
End Sub

我只想将我的 destpath 中的所有 pdf 文件发送到 gmail 并且我在“.Attachment”区域中失败了 请指导我

【问题讨论】:

  • “惨遭失败”没有帮助。您收到什么错误消息?您是否单步执行了代码?
  • 什么是DestPath?也许你只是想念一个反斜杠Dir(DestPath & "\*.pdf*")?无法判断。
  • DestPath - "P:\kin\PROJECTS\TARSON\Newfolder1\"

标签: vba pdf gmail attachment


【解决方案1】:

这演示了如何使用Dir 循环浏览文件夹中的文件。

Option Explicit ' Consider this mandatory
' Tools | Options | Editor tab
' Require Variable Declaration
' If desperate declare as Variant

Private Sub attachFilesInFolder()
    
    Dim myMail As MailItem
    Dim olApp As outlook.Application
    
    Dim DestPath As String
    
    Dim stirFilePath As String
    Dim stirFile As String
    
    DestPath = "P:\kin\PROJECTS\TARSON\Newfolder1\"
    stirFilePath = DestPath & "*.pdf"
    
    Debug.Print
    Debug.Print "stirFilePath.......: " & stirFilePath
    
    Set olApp = New outlook.Application
    
    Set myMail = olApp.CreateItem(0)
        
    With myMail
        
        .Subject = "Quote reg for VAM project"
        
        stirFile = dir(stirFilePath)
        Debug.Print "DestPath & stirFile: " & DestPath & stirFile
            
        Do While stirFile <> ""
            Debug.Print "       stirFile....: " & stirFile
            .Attachments.add (DestPath & stirFile)
            stirFile = dir
        Loop
            
    End With
        
    myMail.Display
   
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多