Solved

Exporting VB6 Datagrid to MS-Excel

Posted on 2004-04-29
5
251 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 69

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 69

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 69

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA: Add rows to listbox based on criteria 7 73
Sending a email via excel using vba 6 71
vb6 connector to SQL Server 2 34
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 41
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now