Solved

Exporting VB6 Datagrid to MS-Excel

Posted on 2004-04-29
5
263 Views
Last Modified: 2012-05-04
I want to export the contents of my datagrid to an excel document..

what i have is almost working, except it will only send over the visible information... (i.e if the contents of the datagrid is longer than 1 page, it will not send the information contained "off the page" to excel).  In the code itselfI have "VisibleRows" in it... there is no other argument I can find for DataGrid ...

This is the code I'm using:

Dim Appli as New Excel.Application
Appli.SheetsInNewWorkbook = 1
   Appli.Visible=True
   Appli.Workbooks.Add

For i = 0 To DataGrid1.VisibleRows - 1
For j = 0 To DataGrid1.VisibleRows - 1

  DataGrid1.Row = i
  DataGrid1.Col = j

Appli.ActiveSheet.cells(i + 1, j + 1).Value = DataGrid1.Text
Next
Next
0
Comment
Question by:NO_CARRIER
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 10951310
I use this to go through a datagrid:

For intRow = 0 To .ApproxCount - 1
  'Some stuff here...

   'Incrémente la ligne (ne surtout pas enlever le "On error...")
   On Error Resume Next
   .Row = .Row + 1
   On Error GoTo 0
Next intRow
0
 
LVL 1

Author Comment

by:NO_CARRIER
ID: 11015478
hmm... I can't get it to export the complete datagrid.. only visible cells.
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 70 total points
ID: 11015748
You can use this code to be sure you are the top:

Public Sub GridGotoTop()
    With gctlDataGrid
        If Not (.DataSource Is Nothing) Then
            If .VisibleRows < .ApproxCount Then
                On Error Resume Next
                Do While True
                    .Scroll 0, -10
                    .FirstRow = 0
                    If Err.Number <> 0 Then Exit Do
                Loop
                On Error GoTo 0
            End If
            If .ApproxCount > 0 Then
                .Col = 0
                .Row = 0
            End If
        End If
    End With
End Sub

then loop through the grid with the code I have provided before.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 11255850
points to emoreau
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 104
passing parameter in sql procedure 9 70
How to read File Date Created using VB6 8 70
Assign a value in Excel V-Basic 3 34
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question