简体   繁体   English

Excel VBA将工作表复制到新工作簿并在Outlook中通过电子邮件发送新工作簿

[英]Excel VBA Copying Sheets to a New Workbook and emailing the New Workbook in Outlook

I have a segment of code that attaches the current file to an e-mail addressed to our sales rep y is equal to the sales rep email. 我有一段代码将当前文件附加到发送给我们的销售代表的电子邮件上,该代码等于销售代表电子邮件。 and to the orders email for our company. 并发送给我们公司的订单电子邮件。

Instead of attaching the whole document to this email I want to copy tabs from the document and paste them into a new document. 我不想将整个文档附加到此电子邮件中,而是要复制文档中的标签并将其粘贴到新文档中。 Then send only the new document (thereby reducing file size and hopefully changing it from a .xlsm attachment to a .xls attachment). 然后仅发送新文档(从而减小文件大小,并希望将其从.xlsm附件更改为.xls附件)。

If ShapesAfter > ShapesBefore Then
    MsgBox "Please Repair Invalid Equipment Selection", , "Invalid Selections _
 Have Been Made"

ElseIf ShapesAfter = ShapesBefore Then
   Sheets("inputs").Select
   Dim y As String
   y = Cells(61, 5).Value
   Sheets("config").Select
  Application.Dialogs(xlDialogSendMail).Show "" & y & "; " & "orders@domainname.com"

Above example is returning Run-time '9' error. 上面的示例返回运行时“ 9”错误。 Here is corrected code: 这是更正的代码:

   Dim wb As Workbook
   Set wb = Workbooks.Add
   ThisWorkbook.Sheets("inputs").Copy After:=wb.Sheets(1)
   ThisWorkbook.Sheets("config").Copy After:=wb.Sheets(1)
   wb.Application.Dialogs(xlDialogSendMail).Show "" & y & "; " & "orders@domainname.com"


   Set wb = Nothing

"ThisWorkbook." “的ThisWorkbook。” has to be added there. 必须在那里添加。

Create a new workbook object and copy the sheets to it. 创建一个新的工作簿对象并将表复制到它。 Example below. 下面的例子。

   Dim wb As Workbook
   Set wb = Workbooks.Add
   Sheets("inputs").Copy After:=wb.Sheets(1)
   Sheets("config").Copy After:=wb.Sheets(1)
   wb.Application.Dialogs(xlDialogSendMail).Show "" & y & "; " & "orders@domainname.com"


  Set wb = Nothing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM