Solved

Using Excel from VB 6 (referencing Excel Dll)

Posted on 2004-04-28
7
941 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 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

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…
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.
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…
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…

737 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