0

我需要一个宏来完成以下工作:

我有一个 6 张工作簿。每个都有不同的名字。工作表名称为 ENT、GHD、T3 等。

我想复制每张工作表的内容并将其保存到具有不同名称以及日期 n 时间戳的不同工作簿中。

例如,表 ENT 必须保存为 XYZ 报告日期时间。Xlsx 和此文件需要附加到 Outlook。

同样,对于 GHD,文件名应该是 ABC Report DATE TIME。XLSX。对于 T3 表和其余 3 张表也是如此。所有这些文件都将邮寄给不同的人。

这些新文件的问题必须保存到创建它的原始文件的文件夹中。

4

2 回答 2

0

所以你想遍历如下的工作表:

for Each xSheet In activeworkbook.worksheets

然后使用工作表名称和工作簿路径调用 saveas 方法

xsheet.saveas activeworkbook.path & xSheet.Name & " Report " & vba.forma(now, "dd mmm yyyy hhmmss"), xlnormal

然后你想创建一个 Outlook 邮件项目,设置收件人、主题和附件,然后发送它......

这样您就可以开始了,然后您只需在引用中添加对 Outlook 应用程序的引用即可使用这些对象...

高温高压

菲利普

于 2013-03-15T17:12:46.700 回答
-1
Sub COMEON()
  Dim onePublishObject As PublishObject
  Dim oneSheet As Worksheet
  Dim scriptingObject As Object
  Dim outlookApplication As Object
  Dim outlookMail As Object
  Dim htmlBody As String
  Dim htmlFile As String
  Dim textStream, fil As String
  Dim dummy As Workbook


  Today = Format(Now(), "dd-mm-yyyy")

  Set dummy = ActiveWorkbook
  Set scriptingObject = CreateObject("Scripting.FileSystemObject")
  Set outlookApplication = CreateObject("Outlook.Application")
  For Each oneSheet In ActiveWorkbook.Worksheets




                                                        Dim StrBody As String
                                                        StrBody = " THIS IS A TEST" & " " & UCase(oneSheet.Name) & " " & "XYZ," & vbNewLine & _
                                                        vbNewLine & _
                                                        "Please FIND ATTACHED <B>'XYZ REPORT'<B>"





    Application.DisplayAlerts = False
    Sheets(oneSheet.Name).Copy
    ActiveWorkbook.SaveAs dummy.Path & "\" & oneSheet.Name & ".xlsx"
    ActiveWorkbook.Close
    Application.DisplayAlerts = True
    Set outlookMail = outlookApplication.CreateItem(0)
    With outlookMail
        .htmlBody = StrBody & htmlBody
        .attachments.Add dummy.Path & "\" & oneSheet.Name & ".xlsx"
        .Display
        .Subject = "XYZ Report" & " " & UCase(oneSheet.Name) & " " & "(" & Today & ")"

    End With
  Next oneSheet
End Sub
于 2013-03-19T05:23:52.553 回答