Solved

Exporting VB6 Datagrid to MS-Excel

Posted on 2004-04-29
5
259 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 / DAO 3.6 / run time error: Couldn't find installable ISAM 7 102
VBA Shell can't Find Word document 11 110
How to Add / Edit Windows Menu 4 67
TT Auto Dashboard 13 95
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

808 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