Full Version: Error with Dim AppExcel as Excel.Application
UtterAccess Discussion Forums > Microsoft® Access > Access Errors + Error Handling
awolterm
I keep getting a complie error:

user - defined type not defined.

CODE
  Private Sub openExcel_Click()
'make a reference to Microsoft excel 9.0 object library
[b]Dim AppExcel As Excel.Application[/b]
Dim wSheet As Worksheet
Dim wBook As Workbook
Set AppExcel = CreateObject("Excel.Application")
If AppExcel.Workbooks.Count = 0 Then
Debug.Print "Adding a new Workbook"
Set wBook = AppExcel.Workbooks.Add
End If

Set wSheet = AppExcel.Sheets(1)
wSheet.Cells(2, 1).Value = "Welcome"
wSheet.Cells(3, 1).Value = "To"
wSheet.Cells(4, 1).Value = "UtterAccess"
AppExcel.Visible = True


End Sub


Anyone know what I get this? I got this code out of the code archive for opening an excel file. It also seems any other code that has the line dim x as excel.application, I get an error.


Thanks for the help.
fkegley
Yes, I believe the problem is that you have not set a reference to the Excel Object library for your computer.
awolterm
Ok 1. How would I do that?
2. How come I can run other db's that use the dim x as excel.application? I have run it out of a couple people's postings in the code archive; however when I move it all to my DB, no go.
freakazeud
Because references don't copy over. Set them manually through VBA editor--Tools--References...or use late binding to avoid the dependency on reference all together.
HTH
Good luck
awolterm
Can you explain more about that?
freakazeud
About what?
HTH
Good luck
awolterm
Sorry I was not specific....

How do I code it with late binding so I don't have to deal with the references?

Sorry, I am just starting out with this excel automation stuff, so I am not quite familiar with the proceedures I need to follow in order to get it to talk.


Thanks for all the help.

Edited by: awolterm on Tue Feb 19 11:22:12 EST 2008.
freakazeud
Hi,
you can read about it in any or all of these:
01
02
03
04
HTH
Good luck
awolterm
Thank you!
freakazeud
You're welcome.
Good luck on future projects!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.