Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Exporting VB6 Datagrid to MS-Excel

Posted on 2004-04-29
5
Medium Priority
?
266 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 210 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
Suggested Courses

609 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