Excel Reference?

R

ryguy7272

I get a tooltip telling me that: Name 'EXL' is not declared and EXL has a
squiggle line under it. I went to Project > Add Reference > COM > Microsoft
10.0 Object Library and still get that tooltip popping up.

Code below:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim WSheet As New Excel.Worksheet()
WSheet = EXL.Workbooks.Open("C:\TEST.XLS").Worksheets.Item(1)
EXL.Range("A2:E3").Select()
Dim CData As Excel.Range
CData = EXL.Selection
CData.Sort(Key1:=CData.Range("A2"),
Order1:=Excel.XlSortOrder.xlAscending)
TextBox1.Clear()
Dim iCol, iRow As Integer
For iCol = 1 To 5
For iRow = 0 To 1
TextBox1.AppendText(CData(iRow, iCol).value & vbTab)
Next
TextBox1.AppendText(vbCrLf)
Next
EXL.Workbooks.Close()
End Sub

I'm reading a book with a few of these Office Automation examples; I just
did this with a reference to a MS Word Object so I thought I knew what to do
for this, but apparently not! What am I doing wrong?

Thanks!
Ryan--
 
P

Patrice

The code you show us doesn't declare EXL so for I would say that the error
message could say exactly what is the problem (that is EXL is just not
declared).
 
R

ryguy7272

Thanks Patrice. I added this:
Dim EXL As Excel.Workbook

Then, when I run the project, I get this message: 'object variable or with
block variable not set'

This line i syellow:
WSheet = EXL.Workbooks.Open("C:\TEST.XLS").Worksheets.Item(1)

Any ideas?

Thanks!
Ryan---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top