基于Macro_page工作表中的3个不同单元格的组合,并包含在单元格C18中(s:\ my drive \ customers \ payroll \ payroll \ timesheets \ timesheets \ february_2025)
the acro运行到ActivesHeet.exportasFixedFormat并停止,但我不知道其背后的原因。任何解决此问题的协助都将不胜感激。 below是我正在使用的代码:
Sub CreateEmail()
CreateEmail Macro
Dim objOutlook As Object
Dim objMail As Object
Dim signature As String
Sheets("Macro_Page").Select
filepath = Range("C18").Value
Sheets("TimeSheets_Summary").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
filepath, Quality:=xlQualityStandard, IncludeDocProperties _
:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Sheets("Macro_Page").Select
PDF_File = "C20"
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With objMail
.Display
End With
signature = objMail.HTMLbody
With objMail
.To = ActiveSheet.Range("C20")
.Cc = ActiveSheet.Range("C21")
.Subject = "Company Weekly TimeSheets"
.HTMLbody = "<font face=" & Chr(34) & "Calibri" & Chr(34) & " size=" & Chr(34) & 4 & Chr(34) & ">" & "Hi," & "<br> <br>" & "Please find attached this weeks timesheets" & "<br> <br>" & signature & "</font>"
.Attachments.Add PDF_File
.Save
.Display
End With
Set objOutlook = Nothing
Set objMail = Nothing
End Sub
该代码应该起作用。 macro_page看起来像这样:
代码为:
'Option Explicit must go at the very top of the module.
Option Explicit
Public Sub CreateEmail()
Dim objOutlook As Object
Dim objMail As Object
Dim signature As String
Dim filepath As String
Dim fname As String
With ThisWorkbook.Worksheets("Macro_Page")
filepath = .Range("C18")
fname = .Range("C15")
End With
ThisWorkbook.Worksheets("TimeSheets_Summary").ExportAsFixedFormat _
Type:=xlTypePDF, _
filename:=filepath & "/" & fname, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With objMail
.display
signature = .htmlbody
.To = ThisWorkbook.Worksheets("Macro_Page").Range("C20")
.CC = ThisWorkbook.Worksheets("Macro_Page").Range("C21")
.Subject = "Company Weekly TimeSheets"
.htmlbody = "<font face=" & Chr(34) & "Calibri" & Chr(34) & " size=" & Chr(34) & 4 & Chr(34) & ">" & "Hi," & "<br> <br>" & "Please find attached this weeks timesheets" & "<br> <br>" & signature & "</font>"
.Attachments.Add filepath & "/" & fname & ".pdf"
.display
End With
Set objOutlook = Nothing
Set objMail = Nothing
End Sub