'Main Module
'Edited by aaa on 18-11-2015
Option Explicit
Public strAttachment As String
Public StrWarnings As String
Sub CreateReport()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim arrList As Variant
Dim WBOutput As Workbook 'This in the newly added workbook
Dim shtAPAC As Worksheet 'This is Sheet1 of the newly added workbook
Dim shtEU As Worksheet 'Add another Worksheet in newly added Workbook
Dim shtNA As Worksheet 'Add another Worksheet in newly added Workbook
Dim strSubjectLine As String 'Not used anywhere
'Clear contents from Main Sheet of the macro
Range("F1:J1").ClearContents
'Check for row data
'This is the Last Row of Main sheet - 6 starting rows.
If shtMain.Range("A17").CurrentRegion.Rows.Count < 2 Then: MsgBox "Raw data is missing!", vbInformation, "Missing Data": Exit Sub
If OutlookExists = False Then Exit Sub
'Working with RowData
With shtRawData
If .AutoFilterMode = True Then .Cells.AutoFilter
'Mapping Sheet of Macro gets activate
.Activate
.Cells.Clear
ActiveWindow.DisplayFormulas = False
arrList = Array("Trans Ccy", "Debit Account", "Credit Account", "Trans Amt", "Initiator", "Initiator CC", "Debit Account Description", "Debit Account Type", "Debit Account Stream", "Credit Account Description", "Credit Account Type", "Credit Account Stream", "Effective Date", "Event Status", "Trans Type", "Jrnl Description", "Qty", "Cusip", "Cusip Description", "Event Entry Time (GMT)", "Eligible Authorizers", "Authorization Category", "Authorization Categories", "Comments", "Event OID", "Mnemonic", "Jrnl Code", "Order Number", "Base Amt", "Base Ccy", "Reason Code", "Approver", "A/M Indicator", "FAC", "Authorization Time (GMT)", "Authorization Comment", "Event VID", "Event RID", "Action OID", "Action VID", "Action RID")
If IsColomunMissing(arrList, shtMain, shtMain.Range("7:7")) = True Then Exit Sub
.Range("A1:AO1").Value = arrList
shtMain.Range("A17").CurrentRegion.AdvancedFilter xlFilterCopy, "", .Range("A1").CurrentRegion
End With
'Creating Output File
Set WBOutput = Workbooks.Add
Set shtAPAC = WBOutput.Sheets(1)
Set shtEU = WBOutput.Worksheets.Add
Set shtNA = WBOutput.Worksheets.Add
shtAPAC.Name = "APAC"
shtEU.Name = "EU"
shtNA.Name = "NA"
shtPrepareFinalTable.Cells.Clear
FilterDataByRegion WBOutput, shtAPAC
FilterDataByRegion WBOutput, shtEU
FilterDataByRegion WBOutput, shtNA
shtMain.Activate
WBOutput.SaveAs ThisWorkbook.Path & Application.PathSeparator & "Wash Accounts report " & Format(Date, "dd.mm.yyyy") & ".xlsx"
strAttachment = WBOutput.FullName
WBOutput.Close False
'Warnigns
shtMain.Activate
shtMain.Range("F1").Value = StrWarnings
'MsgBox "Mail is Drafted." & vbCrLf & vbCrLf & "Warnigs :" & vbCrLf & StrWarnings
StrWarnings = ""
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub