by Chris Beckingham (6 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 15th May 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Export an msFlexGrid to an excel spreadsheet
Dim appExcel As Excel.Application
Dim wrkExcel As Excel.Workbook
Dim shtExcel As Excel.Worksheet
Dim intNewSheets As Integer
Dim llRow As Long
Dim llCol As Long
On Error Resume Next
Set appExcel = GetObject(, "Excel.Application")
If appExcel Is Nothing Then
Set appExcel = CreateObject("Excel.Application")
If appExcel Is Nothing Then
MsgBox "Cannot Open Microsoft Excel For Export", vbCritical
Exit Sub
End If
End If
intNewSheets = appExcel.SheetsInNewWorkbook
appExcel.SheetsInNewWorkbook = 1
Set wrkExcel = appExcel.Workbooks.Add
appExcel.SheetsInNewWorkbook = intNewSheets
Set shtExcel = wrkExcel.Sheets(1)
With shtExcel
For llRow = 0 To aoFG.Rows - 1
For llCol = 0 To aoFG.Cols - 1
shtExcel.Cells(llRow + 1, llCol + 1).Value = aoFG.TextMatrix(llRow, llCol)
Next
Next
End With
shtExcel.Range("A1").Select
appExcel.DisplayFullScreen = True
appExcel.DisplayFullScreen = False
appExcel.Visible = True
Set shtExcel = Nothing
Set wrkExcel = Nothing
Set appExcel = Nothing
End Sub