Solved

Using Excel from VB 6 (referencing Excel Dll)

Posted on 2004-04-28
7
935 Views
Last Modified: 2012-06-21
Hi,

If there are different versions being used for Excel in the company.
How do I make sure that my program doesn't break if I reference Excel lib 10 from my program and users have older or newer versions of excel installed on their machines.

Thanks
0
Comment
Question by:jupiterz
7 Comments
 
LVL 24

Accepted Solution

by:
R_Rajesh earned 250 total points
ID: 10941658
Jupiterz,

use late binding. check out the accepted comment in this link:
http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_20947782.html

Rajesh
0
 

Author Comment

by:jupiterz
ID: 10941851
   Looking at the accepted answer, I modified my code which is listed below.
    My question is if i just change the declaration of the xlApp variable from
   Dim xlApp As  Excel.Application to
   dim xlApp as Object  Does it mean I am late binding? I tested my code it works fine.
   Looking at the code if you can tell me i have done late binding or if it requires any other changes



    Dim sFileName As String
    Dim sPath As String
    Dim xlApp As Object  'Excel.Application
    Dim xlBook As Object 'Excel.Workbook
    Dim xlSheet As Object 'Excel.Worksheet
    Dim i As Integer
    Dim j As Integer
    Dim fld As ADODB.Field

    sFileName = "Report1.xls"
   
    frmTestQueries.cdb.Filter = "Excel Docs (*.xls)|*.xls"
    frmTestQueries.cdb.FileName = sFileName
    frmTestQueries.cdb.ShowSave
   
    sPath = frmTestQueries.cdb.FileName
   
    'open the excel spreadsheet for write
    Set xlApp = CreateObject("Excel.Application")
   
     Set xlBook = xlApp.Workbooks.Add
   
    Set xlSheet = xlBook.Worksheets.Item(1)
   
    'Get other rows
    rs.MoveFirst
    For i = 1 To rs.RecordCount
        For j = 0 To rs.Fields.Count - 1
            If i = 1 Then
                xlSheet.Cells(1, j + 1).Value = rs(j).Name
            End If
            xlSheet.Cells(i, j + 1).Value = rs(j).Value
        Next j
    rs.MoveNext
    Next i
   
    'format cell column widths
    xlSheet.Columns.AutoFit
   
    xlBook.SaveAs (sPath)
    xlApp.Quit
   
    Set xlApp = Nothing
    Set xlBook = Nothing
    Set xlApp = Nothing
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 10942009
the code looks fine. ofcourse, you can always post back if you run into trouble in future :)
you might want to go through this:
http://word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm

Rajesh
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 26

Expert Comment

by:EDDYKT
ID: 10942171
Also make sure you take out all excel reference from References
0
 

Author Comment

by:jupiterz
ID: 10942177
Thanks Rajesh. Got what I asked for...
0
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 10942237
thanks for the grade, jupiterz
:)
R
0
 

Expert Comment

by:reena_pathak
ID: 11291292
Thanks,
This code was really helpful.
-Reena
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 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

10 Experts available now in Live!

Get 1:1 Help Now