Vba 填妥的表格作为空白附件发送

Vba 填妥的表格作为空白附件发送,vba,excel,Vba,Excel,我在Excel中设计了一个表单,供用户填写并单击提交。然后,这将自动将填写好的表单作为附件发送到指定的Outlook电子邮件地址 我遇到的问题是 它发送一张空白表格。该表单将由公司内的多个用户使用,并将从共享驱动器访问 用户无法判断submit按钮是否工作,因为它不显示任何消息。我想显示一条消息“您的表单现在已提交” 这是我目前拥有的代码 Option Explicit Private Sub CommandButton1_Click() On Error GoTo ErrHandler

我在Excel中设计了一个表单,供用户填写并单击提交。然后,这将自动将填写好的表单作为附件发送到指定的Outlook电子邮件地址

我遇到的问题是

  • 它发送一张空白表格。该表单将由公司内的多个用户使用,并将从共享驱动器访问

  • 用户无法判断submit按钮是否工作,因为它不显示任何消息。我想显示一条消息“您的表单现在已提交”

  • 这是我目前拥有的代码

    Option Explicit
    
    Private Sub CommandButton1_Click()
    
    On Error GoTo ErrHandler
    
    ' SET Outlook APPLICATION OBJECT.
    Dim objOutlook As Object
    Set objOutlook = CreateObject("Outlook.Application")
    
    ' CREATE EMAIL OBJECT.
    Dim objEmail As Object
    Set objEmail = objOutlook.CreateItem(olMailItem)
    
    With objEmail
        .To = "jack@jill.com"
        .Subject = "Issue Resolution Request"
        .Body = "Hi Finance Systems, please see the attached issues log for your attention"
        ThisWorkbook.Save
        .Attachment.Add ThisWorkbook.Path & "\" & ThisWorkbook.Name
        .Send        ' SEND THE MESSAGE
    End With
    
    Set objEmail = Nothing:    Set objOutlook = Nothing
    
    ErrHandler:
    
    End Sub
    

    试试这个(这个的一些变体:)


    直接将表格发送到日志不是更容易吗?您可以告诉vba将日志作为任何文件类型发送到目标。这将减少电子邮件的混乱并简化流程。此外,您可以使用电子邮件,然后在单独的一行中将文件转储到首选位置,这样您就不再需要附件。我生成的一个宏使用XML实现了这一点。想看一些示例代码吗?另外值得一提的是,在您的代码中,您没有告诉userform如何处理用户输入
     Private Declare Function ShellExecute Lib "shell32.dll" _
     Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
     ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _
     ByVal nShowCmd As Long) As Long
    
     sub nameofsub()
    
     Dim Email As String, Subj As String
     Dim answer As Integer
     Dim Msg As String, body As String, URL As String
     Dim OutApp As Object, OutMail As Object
     Dim filelocation1 As String
     Dim wb1 as workbook
    
     filelocation1 = "Filepath" & "\" & "filename" & ".filextension"
     CreateObject("Scripting.FileSystemObject").FileExists(filelocation1)
    
     'code to tell user form how to store information in the document
     'Example: (assuming you use excel as a format)
     'Set wb1 = Workbooks.open(filelocation1)
     ' wb1.worksheet.range("a1").value = textbox1.value     this might be off, double check. this might drastically differ is you use other file extensions 
    
    
     Email = "personMcDude@someaddress.com"
     Subj = "My email to you"
     body = "Hello Person," & vbCr & _
             "the stuff is in the folder" & vbCr & _
             "stuff" & vbCr & _
             "more stuff" & vbCr & _
             "and yet more" & vbCr & _
             "Thank you. "
    
     Set OutApp = CreateObject("Outlook.Application")
     Set OutMail = OutApp.CreateItem(0)
    
     On Error Resume Next
         With OutMail
             .To = Email
             .CC = vbNullString
             .BCC = vbNullString
             .Subject = Subj
             .body = body
             .Display
         End With
     On Error GoTo 0
    
     Set OutMail = Nothing
     Set OutApp = Nothing
    
    
     End Sub