Hi,
Here's the sub
The macro import is the 6th last line, commented out.
I've scanned the net and I'm getting the impression it may be impossible or only possible by making Register changes. It may be that being able to code a security change into a new workbook is considered a nono.
Please, don't spend any serious time on as the output isn't frequently used and we can simply import a macro to do the formating.
In advance, many thanks
Private Sub ouputReport()
Dim IntCount As Integer
'Excel declaration
Dim xlApp As New Excel.Application
Dim xlSheet As New Excel.Worksheet
Dim xlWorkbook As New Excel.Workbook
Dim intWidth As Integer
Dim intNumbChannels As Integer
Dim intNumbMnths As Integer
Dim intMonthStart As Integer
Dim intMonthEnd As Integer
Dim intMonthsDone As Integer
Dim intNumbRootCauses As Integer
Dim intChCnt As Integer
Dim intMonthCnt As Integer
Dim intAllCnt As Integer
Dim intRootCnt As Integer
Dim strMonth As String
Dim rngMerge As Range
Set xlApp = CreateObject("Excel.Application")
Set xlWorkbook = xlApp.Workbooks.Add
Set xlSheet = xlWorkbook.Sheets(1)
xlApp.Visible = True
xlSheet.Cells(1, 2).Value = " Successful Delivery Index.... " & Now()
intNumbRootCauses = UBound(strRootHeadings)
'Root cause index row headings
outputRootDetails xlSheet, intNumbRootCauses
Select Case frmReportType.Value
Case 1 'System and Channels
intNumbChannels = UBound(strChHeadings())
Select Case frmDateRange.Value
Case 1 'Season to date
xlSheet.Cells(3, 1).Value = "Report type:"
xlSheet.Cells(3, 2).Value = "Season to Date - System & Channels"
xlSheet.Cells(4, 1).Value = "Season:"
xlSheet.Cells(4, 2).Value = IIf(Month(Now()) > 5, Year(Now()) & "/" & Year(Now()) + 1, Year(Now()) - 1 & "/" & Year(Now()))
xlSheet.Cells(6, 2).Value = "Root Cause Index"
xlSheet.Cells(6, 4).Value = "System"
Case 2 'Date range
xlSheet.Cells(3, 1).Value = "Report type:"
xlSheet.Cells(3, 2).Value = "Date Range - System & Channels"
xlSheet.Cells(4, 1).Value = "Start Date:"
xlSheet.Cells(4, 2).Value = "'" & Me!txtStartDate & "'"
xlSheet.Cells(5, 1).Value = "End Date:"
xlSheet.Cells(5, 2).Value = "'" & Me!txtEndDate & "'"
End Select
'Channel headings
outputChHeadings xlSheet, intNumbChannels
'General and Root data
outputGeneralCHData xlSheet, intNumbChannels, intNumbRootCauses
Case 2 'System by Month
intNumbMnths = UBound(intMnthRoot(), 1)
intMonthStart = Month(strDayMonthSeasonStart)
intMonthEnd = Month(strDayMonthSeasonEnd)
Select Case frmDateRange.Value
Case 1 'Season to date
xlSheet.Cells(3, 1).Value = "Report type:"
xlSheet.Cells(3, 2).Value = "Season to Date - Monthly by System"
xlSheet.Cells(4, 1).Value = "Season:"
xlSheet.Cells(4, 2).Value = IIf(Month(Now()) > 5, Year(Now()) & "/" & Year(Now()) + 1, Year(Now()) - 1 & "/" & Year(Now()))
Case 2 'Date range
xlSheet.Cells(3, 1).Value = "Report type:"
xlSheet.Cells(3, 2).Value = "Date Range - Monthly by System"
xlSheet.Cells(4, 1).Value = "Start Date:"
xlSheet.Cells(4, 2).Value = "'" & Me!txtStartDate & "'"
xlSheet.Cells(5, 1).Value = "End Date:"
xlSheet.Cells(5, 2).Value = "'" & Me!txtEndDate & "'"
End Select
'Month headings
outputMnthHeadings xlSheet, intMonthStart, intMonthEnd
'General and Root data
outputGeneralMnthData xlSheet, intNumbMnths, intNumbRootCauses
Case 3 'SubSystem by Month
intNumbMnths = UBound(intMnthRoot(), 1)
intMonthStart = Month(strDayMonthSeasonStart)
intMonthEnd = Month(strDayMonthSeasonEnd)
Select Case frmDateRange.Value
Case 1 'Season to date
xlSheet.Cells(3, 1).Value = "Report type:"
xlSheet.Cells(3, 2).Value = "Season to Date - SubSystem by Month"
xlSheet.Cells(4, 1).Value = "SubSystem:"
xlSheet.Cells(4, 2).Value = Me!cboFilter
xlSheet.Cells(5, 1).Value = "Season:"
xlSheet.Cells(5, 2).Value = IIf(Month(Now()) > 5, Year(Now()) & "/" & Year(Now()) + 1, Year(Now()) - 1 & "/" & Year(Now()))
Case 2 'Date range
xlSheet.Cells(3, 1).Value = "Report type:"
xlSheet.Cells(3, 2).Value = "Date Range - SubSystem by Month"
xlSheet.Cells(4, 1).Value = "SubSystem:"
xlSheet.Cells(4, 2).Value = Me!cboFilter
xlSheet.Cells(5, 1).Value = "Start Date:"
xlSheet.Cells(5, 2).Value = "'" & Me!txtStartDate & "'"
xlSheet.Cells(6, 1).Value = "End Date:"
xlSheet.Cells(6, 2).Value = "'" & Me!txtEndDate & "'"
End Select
'Month headings
outputMnthHeadings xlSheet, intMonthStart, intMonthEnd
'General and Root data
outputGeneralMnthData xlSheet, intNumbMnths, intNumbRootCauses
Case 4 'Channel by Month
intNumbMnths = UBound(intMnthRoot(), 1)
intMonthStart = Month(strDayMonthSeasonStart)
intMonthEnd = Month(strDayMonthSeasonEnd)
Select Case frmDateRange.Value
Case 1 'Season to date
xlSheet.Cells(3, 1).Value = "Report type:"
xlSheet.Cells(3, 2).Value = "Season to Date - Channel by Month"
xlSheet.Cells(4, 1).Value = "Channel:"
xlSheet.Cells(4, 2).Value = Me!cboFilter
xlSheet.Cells(5, 1).Value = "Season:"
xlSheet.Cells(5, 2).Value = IIf(Month(Now()) > 5, Year(Now()) & "/" & Year(Now()) + 1, Year(Now()) - 1 & "/" & Year(Now()))
Case 2 'Date range
xlSheet.Cells(3, 1).Value = "Report type:"
xlSheet.Cells(3, 2).Value = "Date Range - Channel by Month"
xlSheet.Cells(4, 1).Value = "Channel:"
xlSheet.Cells(4, 2).Value = Me!cboFilter
xlSheet.Cells(5, 1).Value = "Start Date:"
xlSheet.Cells(5, 2).Value = "'" & Me!txtStartDate & "'"
xlSheet.Cells(6, 1).Value = "End Date:"
xlSheet.Cells(6, 2).Value = "'" & Me!txtEndDate & "'"
End Select
'Month headings
outputMnthHeadings xlSheet, intMonthStart, intMonthEnd
'General and Root data
outputGeneralMnthData xlSheet, intNumbMnths, intNumbRootCauses
Case 5 'Outlet by Month
intNumbMnths = UBound(intMnthRoot(), 1)
intMonthStart = Month(strDayMonthSeasonStart)
intMonthEnd = Month(strDayMonthSeasonEnd)
Select Case frmDateRange.Value
Case 1 'Season to date
xlSheet.Cells(3, 1).Value = "Report type:"
xlSheet.Cells(3, 2).Value = "Season to Date - Outlet by Month"
xlSheet.Cells(4, 1).Value = "Outlet:"
xlSheet.Cells(4, 2).Value = Me!cboFilter
xlSheet.Cells(5, 1).Value = "Season:"
xlSheet.Cells(5, 2).Value = IIf(Month(Now()) > 5, Year(Now()) & "/" & Year(Now()) + 1, Year(Now()) - 1 & "/" & Year(Now()))
Case 2 'Date range
xlSheet.Cells(3, 1).Value = "Report type:"
xlSheet.Cells(3, 2).Value = "Date Range - Outlet by Month"
xlSheet.Cells(4, 1).Value = "Outlet:"
xlSheet.Cells(4, 2).Value = Me!cboFilter
xlSheet.Cells(5, 1).Value = "Start Date:"
xlSheet.Cells(5, 2).Value = "'" & Me!txtStartDate & "'"
xlSheet.Cells(6, 1).Value = "End Date:"
xlSheet.Cells(6, 2).Value = "'" & Me!txtEndDate & "'"
End Select
'Month headings
outputMnthHeadings xlSheet, intMonthStart, intMonthEnd
'General and Root data
outputGeneralMnthData xlSheet, intNumbMnths, intNumbRootCauses
End Select
xlSheet.Cells.Columns.AutoFit
xlSheet.PageSetup.PrintGridlines = True
xlSheet.PageSetup.Orientation = xlLandscape
xlSheet.PageSetup.LeftMargin = 0.15
xlSheet.PageSetup.RightMargin = 0.15
'xlApp.VBE.activeVBproject.vbcomponents.Import strSDI_Formater
xlApp.Visible = True
xlApp.Quit
Set xlSheet = Nothing
Set xlWorkbook = Nothing
Set xlApp = Nothing
End Sub