Excel : User-defined type not define 
Author Message
 Excel : User-defined type not define

I have a very simple codes which I download the excel file from a web
site.  If I use the downloaded excel file and run the macro, it works
fine...however, when I copy those codes and paste to the new excel
file, it give me an error message on the line
"  Dim conn As New Connection"
"Complile  Error :  User-defined type not define "

Does nayone know the reason of that ??

-------------------------- Below is the codes which work which
download from the web  ------------------

Sub intro()
  Dim conn As New Connection
  Dim rec As New Recordset
  Dim ws As Worksheet
  Dim sql$, i&
  Set ws = ThisWorkbook.Worksheets("intro")
  conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
    "Data Source=c:\a\db.mdb;"
  sql = "SELECT COMPANY_ANNOUNCEMENT_TEXT " & _
        "FROM  [1Q97 Extract 011 or 012]"
  rec.Open sql, conn
  While Not rec.EOF
    i = i + 1
    ws.[a1].Cells(i, 1) = CStr(rec!COMPANY_ANNOUNCEMENT_TEXT)
    rec.MoveNext
  Wend
  rec.Close: conn.Close
End Sub

----------------------------
Ivan Lee
http://www.*-*-*.com/



Mon, 21 Feb 2005 23:06:26 GMT  
 Excel : User-defined type not define
Hi,
Using the "Connection" object relies on object libraries which must be
referenced by your project so that it may use them - this would've already
been done by the original author of the downloaded file.

In the VBA editor, click Tools -> References...
Browse the list and select "Microsoft DAO 3.6 Object Library". Then click ok
and recompile.

Michael


Quote:
> I have a very simple codes which I download the excel file from a web
> site.  If I use the downloaded excel file and run the macro, it works
> fine...however, when I copy those codes and paste to the new excel
> file, it give me an error message on the line
> "  Dim conn As New Connection"
> "Complile  Error :  User-defined type not define "

> Does nayone know the reason of that ??

> -------------------------- Below is the codes which work which
> download from the web  ------------------

> Sub intro()
>   Dim conn As New Connection
>   Dim rec As New Recordset
>   Dim ws As Worksheet
>   Dim sql$, i&
>   Set ws = ThisWorkbook.Worksheets("intro")
>   conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
>     "Data Source=c:\a\db.mdb;"
>   sql = "SELECT COMPANY_ANNOUNCEMENT_TEXT " & _
>         "FROM  [1Q97 Extract 011 or 012]"
>   rec.Open sql, conn
>   While Not rec.EOF
>     i = i + 1
>     ws.[a1].Cells(i, 1) = CStr(rec!COMPANY_ANNOUNCEMENT_TEXT)
>     rec.MoveNext
>   Wend
>   rec.Close: conn.Close
> End Sub

> ----------------------------
> Ivan Lee
> http://www.geocities.com/ginola79/



Tue, 22 Feb 2005 00:06:12 GMT  
 Excel : User-defined type not define
thousands thanks....
because I haven't written VBA much in Excel...thanks  : )

Quote:
>Hi,
>Using the "Connection" object relies on object libraries which must be
>referenced by your project so that it may use them - this would've already
>been done by the original author of the downloaded file.

>In the VBA editor, click Tools -> References...
>Browse the list and select "Microsoft DAO 3.6 Object Library". Then click ok
>and recompile.

>Michael



>> I have a very simple codes which I download the excel file from a web
>> site.  If I use the downloaded excel file and run the macro, it works
>> fine...however, when I copy those codes and paste to the new excel
>> file, it give me an error message on the line
>> "  Dim conn As New Connection"
>> "Complile  Error :  User-defined type not define "

>> Does nayone know the reason of that ??

>> -------------------------- Below is the codes which work which
>> download from the web  ------------------

>> Sub intro()
>>   Dim conn As New Connection
>>   Dim rec As New Recordset
>>   Dim ws As Worksheet
>>   Dim sql$, i&
>>   Set ws = ThisWorkbook.Worksheets("intro")
>>   conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
>>     "Data Source=c:\a\db.mdb;"
>>   sql = "SELECT COMPANY_ANNOUNCEMENT_TEXT " & _
>>         "FROM  [1Q97 Extract 011 or 012]"
>>   rec.Open sql, conn
>>   While Not rec.EOF
>>     i = i + 1
>>     ws.[a1].Cells(i, 1) = CStr(rec!COMPANY_ANNOUNCEMENT_TEXT)
>>     rec.MoveNext
>>   Wend
>>   rec.Close: conn.Close
>> End Sub

>> ----------------------------
>> Ivan Lee
>> http://www.geocities.com/ginola79/

----------------------------
Ivan Lee
http://www.geocities.com/ginola79/


Tue, 22 Feb 2005 00:31:01 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. User Control - User-defined type not defined

2. User Defined Type Not Defined

3. Compile Error: User-defined type not defined

4. User-defined type not defined (Access 97)

5. Compile Error - User defined type not defined

6. User-defined type not defined (Access 2000)

7. Dim oappWD as Word.Application: User defined type not defined

8. User- Defined type not defined

9. User Define Type Not Defined

10. FileSystemObject "User Defined Type Not Defined"

11. Compile Error - User-Defined type not defined

12. "User defined type, not defined"

 

 
Powered by phpBB® Forum Software