Solved

Exporting VB6 Datagrid to MS-Excel

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

13 Experts available now in Live!

Get 1:1 Help Now