How can we make a universal function?
Cells(1, iCols) ld True lorIndex 2 lorIndex.HorizontalAlignment xlCenter End With and 'Some formatting to make things pretty!
Hopefully it can help someone else!Citrix User Group Community (cugc join this new online community of technology professionals dedicated to helping members and their businesses excel through education, knowledge-sharing, networking and influence.Cells(lStartRow 1, lStartCol).CopyFromRecordset rs 'Some formatting to make things pretty!This is the beauty of VBA once you truly get into it, you can develop some true coding gems that can be utilized in all sorts of situations.Cells(lStartRow, lStartCol iCols - 1) ld True lorIndex 2 lorIndex.HorizontalAlignment xlCenter End With 'Copy the data from our query into Excel ' oExcelWrkSht.Cells(lStartRow, lStartCol iCols).Value me Next backpack 2 teacher book 'Format the header With lStartCol _ oExcelWrkSht.Cells(lStartRow, lStartCol).Select Else MsgBox "There are no records returned by the specified queries/SQL statement.Download SDKs, code snippets and APIs.Core editing is free for consumers on devices avg pc tuneup 2011 activation code with screen sizes.1 inches or less.How could we make if flexible enough to even allow the user to specify an exist workbook to export english grammar learning book pdf to, and if none is specified then create a new one.So let reexamine the above function, how could we modify it to not need to actually remove sections of code depending on whether or not we want autofilters applies, or freeze panes?' 'Freeze pane If bFreezePanes True Then oExcelWrkSht.Connect with experts and join the conversation about Citrix technologies.Android is a trademark of Google Inc.Cells(1, iCols)toFit 'Some formatting to make things pretty!Enterprise Product Self Help, file Sharing and Productivity apps support.As you can see by examining the code it includes Conditional Compiling Directive so you can have it either as Early or Late Binding to suit your preferences.Cells(1, iCols) ld True lorIndex 2 lorIndex.HorizontalAlignment xlCenter End With 'Copy the data from our query into Excel ' pyFromRecordset rs 'Some formatting to make things pretty!Now the above functions does exactly as intended, but what if we wanted more flexibility and more control over what is applied depending on the situation!WorkSheet #Else 'Late Binding Declaration/Constants Dim oExcel As Object Dim oExcelWrkBk As Object Dim oExcelWrkSht As Object Const xlCenter -4108 #End If Dim bExcelOpened As Boolean Dim iCols As Integer Dim lWrkBk As Long 'Start Excel On Error Resume Next Set oExcel GetObject "Excel._ vbCritical vbOKOnly, "No data to generate an Excel spreadsheet with" GoTo Error_Handler_Exit End If End With Error_Handler_Exit: On Error Resume Next sible True 'Make excel visible to the user Set rs Nothing Set oExcelWrkSht Nothing Set oExcelWrkBk Nothing reenUpdating True Set oExcel Nothing Exit.
' ' Input Variables: ' ' rs : Recordset object to export to excel ' sFile : Optional - File path and name to udate ' If none is provided a new Excel file is created ' sWrkSht : Optional - Name of the Worksheet.