Results 1 to 3 of 3

Thread: Error loading DLL when use "workbooks.add" on another computer!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    2

    Error loading DLL when use "workbooks.add" on another computer!

    Hello,
    I have a problem with my program. I have a code as follow:
    Code:
    Dim Ex As New Excel.Application
    Dim aa As Excel.Workbook
    Dim ws As Excel.Worksheet
    Set aa = Ex.Workbooks.Add
    aa.SaveAs ("C:\Hong.xls")
    Set ws = aa.Sheets(1)
        Cells(1, 1) = Time
        For i = 2 To 24
            Cells(1, i) = i
        Next
    aa.Save
     aa.Close: Set aa = Nothing: Set Ex = Nothing
    I wrote it on my computer, use VB6.0 and Office 2003. So I used reference: "Excel 11.0 Object Library". The program run perfectly on my computer.
    But I want to use it with another computer which couldn't install Office. So I copied Office 97 (it can run instantly) to the computer and use reference: "Excel 8.0 Object Library". And the program always get error "loading DLL" at" "Set aa=Ex.Workbooks.Add"
    I don't know how to solve this problem.
    Please help me!
    Thank you very much.

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Error loading DLL when use "workbooks.add" on another computer!

    Before compiling your App, remove the reference to Excel and change the code to use Late Binding. This way your App will be Excel Version-independent, your code using late binding would be:
    Code:
    Dim Ex As Object
    Dim aa As Object
    Dim ws As Object
    
        Set Ex = CreateObject("Excel.Application")
        Set aa = Ex.Workbooks.Add
        aa.SaveAs ("C:\Hong.xls")
        Set ws = aa.Sheets(1)
        Cells(1, 1) = Time
        For i = 2 To 24
             Cells(1, i) = i
        Next
        aa.Save
        aa.Close
        Set aa = Nothing
        Set Ex = Nothing
        Set ws = Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    2

    Re: Error loading DLL when use "workbooks.add" on another computer!

    That's great. Thank you so much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width