首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >vba中的.attachment问题

vba中的.attachment问题
EN

Stack Overflow用户
提问于 2021-03-11 19:36:44
回答 1查看 68关注 0票数 0
代码语言:javascript
运行
复制
   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

我只想用gmail发送我的目标路径中的所有pdf文件&我在".Attachment“区域失败得很糟糕,请指导我。

EN

回答 1

Stack Overflow用户

发布于 2021-05-05 22:03:20

这演示了如何使用Dir遍历文件夹中的文件。

代码语言:javascript
运行
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66581781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档