I have an MSFlexgrid on a form in an Access XP database. I would like to export the data in the grid to Excel. I know how to do this in VB, but I am not sure if the same code can be used in Access. When I try it, it gives me run-time error 381 - Subscript out of range
VB Code:
Private Sub cmdExport_Click() On Error Resume Next Dim xLApp As Excel.Application Dim xLWB As Excel.Workbook Dim xLSH As Excel.Worksheet Dim RowCounter As Integer Dim ColCounter As Integer 'open Excel application Set xLApp = CreateObject("Excel.application") 'Create Excel workbook xLApp.Workbooks.Add Set xLWB = xLApp.Workbooks(1) 'Using Sheet 1 Set xLSH = xLWB.Worksheets(1) For RowCounter = 0 To 44 For ColCounter = 0 To 1 With grdPlans xLSH.Cells((StartRow + RowCounter) - 1, (StartCol + ColCounter) - 1).Value = _ .TextMatrix(RowCounter - 1, ColCounter - 1) & " " End With Next Next xLWB.SaveAs (App.Path & "\Plan.xls") xLWB.Close xLApp.Quit Set xLWB = Nothing Set xLApp = Nothing End Sub
Is there a way to do this?




Reply With Quote