?
Solved

Using Excel from VB 6 (referencing Excel Dll)

Posted on 2004-04-28
7
Medium Priority
?
944 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
[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
7 Comments
 
LVL 24

Accepted Solution

by:
R_Rajesh earned 1000 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
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!

 
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

Technology Partners: 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

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…
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…
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…
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…
Suggested Courses

762 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