1

For several years I have been running a compiled VB6 program on an church office computer. I had the vb6 program installed on my home computer (Win 7) This program ran without problems. The program opened Excel spreadsheets and allowed the user to manipulate the data on the spreadsheet.

My Windows 7 computer crashed. I have a Windows 8.1 computer and have loaded vb6 on this computer. The installation appears to be successful except when I run the same visual basic project I get a Runtime Error '-2147319779 Automation Error Library not registered.' A sample of my code is shown below:

Dim oExcel As Excel.Application
    Set oExcel = Excel.Application

    oExcel.Workbooks.Open ("C:\FPCE Financial\FY-2014\2014-01 Financials.xls")
    Application.Visible = True

The error occurs on the "Set oExcel = Excel.Application" line.

Any help would be appreciated.

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Geo.
  • 21
  • 2

1 Answers1

1

If you haven't set a reference to Excel you need to use "Late Binding" to create the Excel object. As @Noodles says - if you don't have Office installed, it won't work period.

Try changing this

Dim oExcel As Excel.Application
Set oExcel = Excel.Application

To this

Dim oExcel As Object
Set oExcel = CreateObject("Excel.Application")
dbmitch
  • 5,361
  • 4
  • 24
  • 38
  • 2
    The project would not compile if a reference to Office was not set. There is no benefit in switching to late binding in this case, unless you want a more challenging coding mode with no intellisense. – GSerg Jul 24 '16 at 16:36
  • 1
    @GSerg - That's non-sense. Late binding doesn't require a reference and will compile just fine. The benefit to switching is that the compiled project will no longer be tied to a specific version of Office. – Comintern Jul 27 '16 at 16:29
  • 1
    @Comintern I was saying that since the OP's project compiles while using early binding, the reference is obviously set in the project settings so it doesn't make sense to suggest what to do when the reference is not set. As for not depending on an Office version, that is also [not a problem](http://stackoverflow.com/a/32790396/11683) because you control which version you are referencing when compiling, so it will work as long as you compile against the lowest Office version you support. – GSerg Jul 27 '16 at 16:57
  • 1
    @GSerg - The post you link to specifically explains that it is a problem: "To avoid this, either always save the file under the earliest Office version that you support, or completely remove the references to other Office apps and use late binding to call them.". The reference is a GUID to a specific version of Office. Late binding requests an instance of a registered *class* from it's registered COM server. This is ***the*** fundamental concept of COM. – Comintern Jul 27 '16 at 17:00
  • @Comintern Yes, "save the file under the earliest Office version that you support" is the option I am suggesting, and the "or completely remove the references to other Office apps and use late binding to call them" is the option I'm saying won't do any additional good here. Also, MS Office is known for treating COM rules as it pleases, including keeping the same ID when updating interfaces and [fiddling with COM identity](http://stackoverflow.com/q/36495738/11683). – GSerg Jul 27 '16 at 17:10
  • @GSerg - I'd suggest reading [Using early binding and late binding in Automation](https://support.microsoft.com/en-us/kb/245115). Let me know if you have any questions. – Comintern Jul 27 '16 at 17:36
  • I don't have any questions @Comintern. It's you who keeps saying my comments are wrong. If you actually tried doing it you would see they are not. – GSerg Jul 27 '16 at 17:41
  • @GSerg - "The project would not compile if a reference to Office was not set." <-- this is objectively wrong. "There is no benefit in switching to late binding in this case, unless you want a more challenging coding mode with no intellisense." <-- this subjectively wrong. You are confusing *document* versioning with binding. – Comintern Jul 27 '16 at 17:44
  • @Comintern The OP uses early binding (see their code). So their project would not compile if a reference to Office was not set, as dbmitch suggested it might have been, there would be a compile-time error about an unknown type `Excel.Application`. Switching to late binding gives you no benefit whatsoever because early binding to Office does not limit you to a particular version of Office; your program will work on computers with newer versions of Office too. To be extra sure I just compiled a VB6 exe with early binding to Excel 2003 and ran it against Excel 2016. So both of these are correct. – GSerg Jul 27 '16 at 17:58