Attribute VB_Name = "modInstallerReport"
Option Explicit

Private Function OfficeFeatureInstallStates() As Boolean
    ' Prints features and installation states to Excel worksheet.

    Dim ofiInstall      As OfficeInstall
    Dim rstFeatures     As ADODB.Recordset
    Dim fldField        As ADODB.Field
    Dim wbkWorkbook     As Excel.Workbook
    Dim wksWorksheet    As Excel.Worksheet
    Dim rngHeader       As Excel.Range
    Dim rngData         As Excel.Range
    Dim lngCount        As Long
    Dim appXL           As Excel.Application
    
    On Error GoTo OfficeFeatureInstallStates_Err
    
    ' Create new instance of OfficeInstall object.
    Set ofiInstall = New OfficeInstall

    ' Return recordset containing features and installation states.
    Set rstFeatures = ofiInstall.GetAllFeatureInstallStates

    ' Return reference to workbook shown in control.
    Set appXL = New Excel.Application
    Set wbkWorkbook = appXL.Workbooks.Add
    wbkWorkbook.Application.Visible = True
    ' Return reference to first worksheet.
    Set wksWorksheet = wbkWorkbook.Worksheets(1)

    ' Return reference to ranges in this workbook.
    Set rngHeader = wksWorksheet.Rows(1)
    Set rngData = wksWorksheet.Range("A2")
    
    lngCount = 1
    ' Write field names to first row in worksheet.
    For Each fldField In rstFeatures.Fields
        rngHeader.Cells(1, lngCount).Value = fldField.Name
        lngCount = lngCount + 1
    Next
    ' Make header cells bold.
    rngHeader.Font.Bold = True
    
    ' Print recordset to worksheet, starting at cell A2.
    rngData.CopyFromRecordset rstFeatures
    
    ' Change font size.
    wksWorksheet.UsedRange.Font.Size = 8
    ' AutoFit columns.
    wksWorksheet.UsedRange.Columns.AutoFit
    ' Check whether AutoFilter is off.
    If wksWorksheet.AutoFilterMode = False Then
        ' Turn AutoFilter on.
        rngHeader.AutoFilter
    End If
    
    OfficeFeatureInstallStates = True
    
OfficeFeatureInstallStates_End:
    On Error Resume Next
    rstFeatures.Close
    Set rstFeatures = Nothing
    Exit Function

OfficeFeatureInstallStates_Err:
    MsgBox "Error #:" & Err.Number & vbCrLf & Err.Description, _
        vbExclamation
    OfficeFeatureInstallStates = False
    Resume OfficeFeatureInstallStates_End
End Function

Sub CreateInstallerReport()
    Dim strMsg As String
    
    If OfficeFeatureInstallStates = False Then
        strMsg = App.Title & " cannot create the Windows " _
            & "Installer report at this time."
        MsgBox strMsg, vbExclamation
    End If
End Sub
