Exporting flexgrid to Excel

L

Lee

I have a 2 column MSFlexgrid on a form that I am exporting
to Excel. The workbook created is saved and named with the
value highlighted in a listbox on the form. This is the
code I am using:

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
Dim PlName As Variant
PlName = Forms!frmgrid!lstPlan

'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 49
For ColCounter = 1 To 3
With grdPlans
xLSH.Cells(RowCounter, ColCounter).Value =
_
.TextMatrix(RowCounter - 1,
ColCounter - 1) & " "
End With
Next
Next

xLWB.SaveAs Application.CurrentProject.Path & "\" &
PlName & " " & "Benefit Summary.xls"
MsgBox ("Your file has been saved to" & " " &
Application.CurrentProject.Path & "\" & PlName & " "
& "Benefit Summary.xls")

xLWB.Close
xLApp.Quit

Set xLWB = Nothing
Set xLApp = Nothing

The grid exports correctly. However, my problem is that
in addition to properly saving and nameing a document, a
second workbook, unnamed is opened and it contains only
the 2nd column of the flexgrid. I cannot figure out what
is causing this. It is not a fatal error, but it is
awkward. Can anyone help?
 
A

Art

Hi Lee:
You say that the grid has two columns but in your code
you are using three columns. Could this be the cause of
your bug?

Hope This Helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top