
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/