--============================================================================================================= -- Application Name: -- Line Inventory System -- -- Code Description: -- This is the code that creates an Excel spreadsheet from the items listed in the datagrid. To create an -- Excel spreadsheet the user had to right click on the mouse over the datagrid, then select 'Send->Excel'. -- --============================================================================================================= Private Function CreateExcelSheet() As Boolean Dim sXLSFile As String Dim wbXL As New Excel.Workbook Dim wsXL As New Excel.Worksheet Dim objXLS As Object Dim intRow As Integer Dim intCol As Integer Dim intField As Integer Dim strTemp As String Dim intIncrement As Integer Dim intCount As Integer On Error GoTo CloseExcel_Err objXLS.Application.Quit On Error GoTo CreateExcelSheet_Error Set objXLS = CreateObject("Excel.Application") If Not IsObject(objXLS) Then MsgBox "You need to have Microsoft Excel installed to use this function", _ vbExclamation + vbOKOnly, "Export to Excel Function" CreateExcelSheet = False Exit Function End If '======================== ' Open Excel '======================== Set wbXL = objXLS.Workbooks.Add Set wsXL = objXLS.ActiveSheet '======================== ' name the worksheet '======================== With wsXL If strViewMode = "GAP" Then .Name = "GAP View" ElseIf strViewMode = "REPORT" Then .Name = Mid(cmbReports.Text, 1, 30) Else .Name = "Line View" End If End With '===================================== ' fill worksheet with Column Headers '===================================== If dgrdNPANXX.Rows > 1 Then frmMessage.Show frmMessage.blnCancel = False frmMessage.Caption = "Create Excel Spreadsheet" frmMessage.Refresh frmMessage.UpdateProgressBar 0, dgrdNPANXX.Rows - 1, "Creating Excel Spreadsheet...", 1 '============================== ' Creating Spreadsheet '============================== objXLS.Visible = False intRow = 0 intCol = 0 intField = 0 intCount = 0 If dgrdNPANXX.Rows <= 10 Then intIncrement = 1 ElseIf dgrdNPANXX.Rows <= 100 Then intIncrement = 5 ElseIf dgrdNPANXX.Rows <= 1000 Then intIncrement = 20 Else intIncrement = 50 End If For intRow = 0 To dgrdNPANXX.Rows - 1 DoEvents intCount = intCount + 1 If frmMessage.blnCancel Then Exit For End If frmMessage.UpdateProgressBar intRow, dgrdNPANXX.Rows - 1, "Creating Excel Spreadsheet...", 0 For intField = 0 To dgrdNPANXX.Cols - 1 wsXL.Cells(intRow + 1, intField + 1).Value = dgrdNPANXX.TextMatrix(intRow, intField) If intRow = 0 Then wsXL.Cells(intRow + 1, intField + 1).Font.Bold = True Else If strViewMode = "GAP" Then dgrdNPANXX.Col = intField dgrdNPANXX.Row = intRow wsXL.Cells(intRow + 1, intField + 1).Font.Bold = False wsXL.Cells(intRow + 1, intField + 1).Interior.Color = dgrdNPANXX.CellBackColor Else wsXL.Cells(intRow + 1, intField + 1).Font.Bold = False End If End If Next intField If intRow = 0 Then strTemp = Right(wsXL.Columns(intField).AddressLocal, 2) & 1 wsXL.Range("a1", strTemp).AutoFormat wsXL.Range("a1", strTemp).Interior.Color = &HCCCCCC End If Next intRow frmMessage.Hide CreateExcelSheet = True objXLS.Visible = True dgrdNPANXX.Row = 1 dgrdNPANXX.Col = 0 dgrdNPANXX.ColSel = dgrdNPANXX.Cols - 1 End If Exit Function