我正在编写一个子邮件,用于生成电子邮件并附上PDF收据和(取决于客户端)excel收据,用于白天完成的业务。由于并非每家公司都收到excel收据,但每家公司都收到PDF收据;
我正在构建处理这些操作的单独函数。
问题:将已创建的Outlook Mail项目传递给函数
收到错误消息:用户定义的类型未定义
位置:错误发生在发布代码底部的私人子网中。 Private Sub BuildPDFConfirmEmail(ByRef outMail As olMailItem, ByVal firmName1 As String, ByVal firmName2 As String, ByVal firmName3 As String, ByVal isTraderSeparate As Boolean)
目前BuildPDFConfirmEmail
内的代码只是用于测试的虚拟代码,直到我能够正常运行
Option Explicit
Private Const EMAIL_BODY As String = "Hello," & "<br><br>" & "Please find today's trade confirmation(s) attached. Thank you." & "<br><br>" & "Best Regards," & "<br>"
Private Const PDF_FILE_PATH As String = "X:\Back Office\Confirm Drop File\"
Private Const EXCEL_CONFIRM_FILE_PATH As String = "X:\Back Office\Confirm Drop File\Excel Confirm Drop File\"
Public Sub SendPdfConfirmEmails()
'Sends PDF confirm emails to clients
'Version 2
Dim appOutLook As outLook.Application
Dim outMail As outLook.MailItem
Dim eeBook As Workbook
Dim reportsByFirmSheet As Worksheet, controlPanelSheet As Worksheet, tradesMasterSheet As Worksheet
Dim firmAlreadyRun As Boolean, isTraderSeparate As Boolean, firmNeedExcelConfirm As Boolean
Dim activeWorkbookName As String, currentFirmName As String, currentTraderName As String, firmEmail As String, firmName1 As String, firmName2 As String, firmName3 As String, formattedReportDate As String
Dim lastRowReportsByFirmSheet As Long, lRowContactsMasterSheet As Long, reportsByFirmRowCounter As Long
Application.ScreenUpdating = False
Application.StatusBar = True
activeWorkbookName = ActiveWorkbook.Name
Set appOutLook = CreateObject("Outlook.Application")
Set outMail = appOutLook.CreateItem(olMailItem)
Set eeBook = Workbooks(activeWorkbookName)
Set reportsByFirmSheet = eeBook.Sheets("ReportsbyFirm")
Set controlPanelSheet = eeBook.Sheets("Control Panel")
Set tradesMasterSheet = eeBook.Sheets("Trades Master List")
'Sets Date parameters in Reports by firm and ensures date linkage between reports by firm and control panel by running control panel routine
reportsByFirmSheet.Cells(1, 2) = controlPanelSheet.Cells(7, 6)
reportsByFirmSheet.Cells(2, 2) = controlPanelSheet.Cells(7, 6)
formattedReportDate = Replace(Format(Range("printinvdate"), "m/d/yy"), "/", ".")
'Call gen_report
'finds last row to create end bound of for loop iteration through Reports By Firm Sheet
lastRowReportsByFirmSheet = reportsByFirmSheet.Cells(reportsByFirmSheet.Rows.Count, "A").End(xlUp).Row
'Iterates through reports by firm and steps down each row to capture all firms and generate emails
For reportsByFirmRowCounter = 11 To lastRowReportsByFirmSheet
currentFirmName = reportsByFirmSheet.Cells(reportsByFirmRowCounter, 5).Value
currentTraderName = reportsByFirmSheet.Cells(reportsByFirmRowCounter, 6).Value
'Tests to see if firm was already run and subsequently if the emp was already run if annotated that emp is seperate in memory manager area
firmAlreadyRun = FirmDidRun(currentFirmName, currentTraderName)
'Skips iteration process and moves to next if firm/trader has already been run
If firmAlreadyRun = True Then GoTo skipIteration
firmEmail = GetFirmEmailInfo(currentFirmName, currentTraderName, isTraderSeparate, firmNeedExcelConfirm, firmName1, firmName2, firmName3)
'tests firmEmail for clients who do not receive emailed confirms
If firmEmail = "NO" Then GoTo skipIteration
'Creates new email object
Set outMail = appOutLook.CreateItem(olMailItem)
Call BuildPDFConfirmEmail(outMail, firmName1, firmName2, firmName3, isTraderSeparate)
skipIteration:
Next
End Sub
Private Sub BuildPDFConfirmEmail(ByRef outMail As olMailItem, ByVal firmName1 As String, ByVal firmName2 As String, ByVal firmName3 As String, ByVal isTraderSeparate As Boolean)
With outMail
.Display
End With
End Sub