|
-
Jul 17th, 2003, 02:12 PM
#1
Thread Starter
Lively Member
Export Access MSFlexgrid to Excel
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?
-
Jul 18th, 2003, 06:33 AM
#2
Member
Check your subscript values
What are the values of and StartRow and StartCol? If they are 0 or 1 when your for loops start you will end up with:
Cells 'row' subscript = 0 + 0 - 1 = -1
Cells 'row' subscript = 1 + 0 - 1 = 0
Both 0 and 1 are invalid in the .Cells(Row,Col) property.
Cells(1,1) is cell "A1".
Also check the starting subscript values you are passing to the TextMatrix of the flexgrid.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|