Library of Types

  • Thread starter Thread starter may
  • Start date Start date
M

may

How to link to library of types excel.workbooks.
I wrote:
Dim xlApp As Object '
Dim wb As Excel.Workbook

Set xlApp = CreateObject("excel.application")
xlApp.Visible = True
wb = xlApp.Workbooks.Open(rst!WhereBase & "\" & "1.xls"

After running, I receved message:
Error of compiling
Has not wrote type
 
may said:
How to link to library of types excel.workbooks.
I wrote:
Dim xlApp As Object '
Dim wb As Excel.Workbook

Set xlApp = CreateObject("excel.application")
xlApp.Visible = True
wb = xlApp.Workbooks.Open(rst!WhereBase & "\" & "1.xls"

After running, I receved message:
Error of compiling
Has not wrote type

If I understand you correctly, you can either:

Choice 1
---------
Set a reference to the Microsoft Excel <version> Object Library. With
your module open in the VB Editor, click Tools -> References..., locate
this library in the list, and put a check mark next to it.

**OR**

Choice 2
---------
Use late binding so you don't need the reference. To do that, change
Dim wb As Excel.Workbook

to

Dim wb As Object

No matter which choice you take, I believe you must change this line:
wb = xlApp.Workbooks.Open(rst!WhereBase & "\" & "1.xls"

to this:

Set wb = xlApp.Workbooks.Open(rst!WhereBase & "\" & "1.xls")

Note the use of the Set keyword, which is required for assigning to an
object variable.
 
Back
Top