Public Function fnTEST()
'////////////////////////////////////////////////////////////////////
'// Function: fnTest
'// XLS Headers Module
'////////////////////////////////////////////////////////////////////
'// Author:
'// Andrew Semenov
'//
http://www.zmey.1977.ru/Excel_And_Autofilter.htm
'// Modified:
'// Date Editor Description
'// =============================================================
'// 13 Aug 2008 Chris Taylor Added comments and formatted for
'// improved readability, removed
'// unused variable "n" from function
'//
'////////////////////////////////////////////////////////////////////
'// Description:
'// sets variables and uses them to created heirarchical headers
'// in an MS Access spreadsheet
'//
'////////////////////////////////////////////////////////////////////
'// Variables:
'// Variable Datatype Description
'// =============================================================
'// XL Object
'// WB Workbook -MS Excel Workbook
'// WS Worksheet -MS Excel Worksheet
'// n Long - ? (not used in function)
'// m Long - ? (not used in function)
'// x Long -MS Excel row number for first cell
'// y Long -MS Excel column number for first cell
'// labels variant -Multidimentional array of labels with
'// a sub array for each row of headers
'// palki boolean -indicator used to add table borders
'//
'//////////////////////////////////////////////////////////////////////
'// Requirements:
'// Microsoft Visual Basic for Applications
'// Microsoft Access 9.0 Object Library
'// Microsoft Excel 9.0 Object Library
'// fnTXLOut (MS
'// fnCreate_Heirarchical_Headers (XLS Headers Module)
'// fnDrawXLSBox (XLS Headers Module)
'//////////////////////////////////////////////////////////////////////
'declare variables
Dim XL As Object
Dim WB As Workbook
Dim WS As Worksheet
Dim n As Long, m As Long
Dim x As Long
Dim y As Long
Dim labels As Variant
'create MS Excel file
Set XL = CreateObject("excel.application")
'set number of worksheets in workbook
XL.SheetsInNewWorkbook = 1
'make MS Excel file visible
XL.Visible = True
'add defined number of worksheet pages to workbook
Set WB = XL.Workbooks.Add
Set WS = WB.Worksheets(1)
'=============================================================================
' begin attempt to populate cells with data below heirarchical headers
'=============================================================================
Dim strSQL As String
strSQL = "SELECT "
strSQL = strSQL & "Chr(39) & [2010].[class] AS Class_,"
strSQL = strSQL & "[2010].Description, "
strSQL = strSQL & "[2010].BCHS, "
strSQL = strSQL & "[2010].BDCHS, "
strSQL = strSQL & "[2010].BLS, "
strSQL = strSQL & "[2010].BPHI, "
strSQL = strSQL & "[2010].BPPM, "
strSQL = strSQL & "[2010].BPS, "
strSQL = strSQL & "[2010].Director, "
strSQL = strSQL & "[2010].HSPR, "
strSQL = strSQL & "[2010].[Non-DPHS], "
strSQL = strSQL & "[2010].Other, "
strSQL = strSQL & "[2010].Total, "
strSQL = strSQL & "[2011].BCHS, "
strSQL = strSQL & "[2011].BDCHS, "
strSQL = strSQL & "[2011].BLS, "
strSQL = strSQL & "[2011].BPHI, "
strSQL = strSQL & "[2011].BPPM, "
strSQL = strSQL & "[2011].BPS, "
strSQL = strSQL & "[2011].Director, "
strSQL = strSQL & "[2011].HSPR, "
strSQL = strSQL & "[2011].[Non-DPHS], "
strSQL = strSQL & "[2011].Other, "
strSQL = strSQL & "[2011].Total "
strSQL = strSQL & "FROM "
strSQL = strSQL & "2010 "
strSQL = strSQL & "INNER JOIN 2011 "
strSQL = strSQL & "ON "
strSQL = strSQL & "([2011].Description = [2010].Description) "
strSQL = strSQL & "AND "
strSQL = strSQL & "([2010].Class = [2011].Class)"
strSQL = strSQL & ";"
x = 1
y = 3
Call fnTXLOut(strSQL, WS, x, y)
'=============================================================================
' end attempt to populate cells with data below heirarchical headers
' return to heirarchical headers function
'=============================================================================
'uncomment different labels for sample
'2 floors simple sample (column titles, and super column titles)
'labels = Array( _
Array("a", "b", "c"), _
Array("1", "2"))
'3 floors (column titles, super column titles, and super super column titles)
'labels = Array( _
Array("a", "b", "c"), _
Array("1", "2"), _
Array("aa", "bb", "cc", "dd"))
'3 floors irregular (column titles, s-column titles, and s-s-column titles irregular number of sub categories)
'labels = Array( _
Array( _
Array("a", "b"), _
Array("1", "2"), _
Array("aa", "bb", "cc", "dd")), _
Array(Array("c"), _
Array("c1", "c2", "c3"), _
Array("ca", "cb", "cc", "cd")))
'OIT Direct Services Report
labels = Array( _
Array("DHHS Office of Information Technology Budget - Direct Services"), _
Array("SFY 2010", "SFY 2011"), _
Array("BCHS", "BDCHS", "BLS", "BPHI", "BPPM", "BPS", "Director", "HSPR", "Non-DPHS", "Other", "Total"))
'set first cell to use when pasting labels
'topleft corner of range where values will be posted
x = 3
y = 1
'Call heirarchical headers function
Call fnCreate_Heirarchical_Headers(WS, x, y, m, labels, True)
'format output after MS Excel spreadsheet has been populated
'Outline Headers
With WS.Range("A1:X3")
.HorizontalAlignment = xlHAlignCenter
.Borders.Weight = xlMedium
End With
'autofit columns
With WS.Range("A1:X49")
.Columns.AutoFit
End With
'center class codes
With WS.Range("A4:A49")
.HorizontalAlignment = xlHAlignCenter
End With
'Outline Data
WS.Range("A1:B2").Merge
Call fnDrawXLSBox(WS, "A4:X45")
With WS.Range("A4:X45")
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
Call fnDrawXLSBox(WS, "A46:X48")
With WS.Range("A46:X48")
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
Call fnDrawXLSBox(WS, "A49:X49")
With WS.Range("A49:X49")
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
Call fnDrawXLSBox(WS, "B1:B49")
Call fnDrawXLSBox(WS, "C2:M49")
Set XL = Nothing
End Function