提问人:Chad 提问时间:11/15/2023 更新时间:11/15/2023 访问量:10
宏自动将单个电子表格从Excel中以CSV格式通过电子邮件发送,仅包含昨天,日期和数据的行
Macro to auto email individual spreadsheets as CSV from Excel with only rows including yesterdays date and data
问:
我正在尝试自动提示 csv 附件以从电子表格中的电子邮件数据,该电子表格仅包含行中列出的昨天日期。到目前为止,我能够发送整个电子表格,但我需要更具体。此外,日期另存为 mm/dd/yyyy,我需要它保持 dd/mm/yyyy 格式。列从 A 到 G,有 391 行,每天更新一个变量
Public Sub Email_Sheets_As_CSV()
Dim csvFile As String
Dim wsName As Variant
Dim OutApp As Object, OutMail As Object
Sheets("MonitorPro").Activate
wsName = ActiveSheet.Name
csvFile = ThisWorkbook.Path & "\" & wsName & ".csv"
ThisWorkbook.ActiveSheet.Copy
ActiveWorkbook.SaveAs csvFile, FileFormat:=xlCSV
ActiveWorkbook.Close False
'Email the .csv files
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = "[email protected]"
.CC = ""
.BCC = ""
.Subject = "Monthly_Daily_Checks_Data"
.Body = "This email contains 1 .csv file attachments."
.Attachments.Add csvFile
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
'Delete the .csv files
End Sub
Public Sub Email_Sheets_As_CSV()
Dim csvFile As String
Dim wsName As Variant
Dim OutApp As Object, OutMail As Object
Sheets("MonitorPro").Activate
wsName = ActiveSheet.Name
csvFile = ThisWorkbook.Path & "\" & wsName & ".csv"
ThisWorkbook.ActiveSheet.Copy
ActiveWorkbook.SaveAs csvFile, FileFormat:=xlCSV
ActiveWorkbook.Close False
'Email the .csv files
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = "[email protected]"
.CC = ""
.BCC = ""
.Subject = "Monthly_Daily_Checks_Data"
.Body = "This email contains 1 .csv file attachments."
.Attachments.Add csvFile
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
'Delete the .csv files
End Sub
答: 暂无答案
评论