Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(Problem) References to Excel Sheet From Visual Basic

Status
Not open for further replies.

frankR40

Programmer
Feb 3, 2004
3
US
I have a Visual Basic program which references data from an Excel sheet and I have a function which calls certain cells in order but changes which row it will be calling on a regular basis. Example code below:

x=Start.xlsheet.Cells(position, 1).Value

where position changes frequently.

When I run though, I get a error "Application-defined or object-defined error", I'm baffled because I've never seen this error, nor does msdn library offer any help at all.

Any help would be appreciated, tks
 
Doing a Google advanced search on "Application-defined or object-defined error" produced more than 700 pages of results with the references to Excel on the first page. Doing a search of those 700+ pages for "Microsoft" produced 401 pages of results. Hope that helps at least a bit.
 
I am confused ...

x=Start.xlsheet.Cells(position, 1).Value

What is Start ?
How did you declare your objects?
Why do you use .value?

Sample code ...

Dim xlsApp As Object
Dim xlsSheet As Object

'See if instance of excel is running
Set xlsApp = GetObject(, "Excel.Application")

If Err.Number > 0 Then
Err.Clear
'Instanciate excel
Set xlsApp = CreateObject("Excel.Application")

''' You can do more error trapping here ... like if there is another error to exit the procedure ... or to set a variable to know if your application should close Excel or not ...

End If

'Open spesified Excel sheet
xlsApp.Workbooks.Open "Your File Name Here"

Set xlsSheet = xlsApp.ActiveSheet

'x = xlsSheet.Cells(ROW, COLUMN)
x = xlsheet.Cells(position, 1)

[flowerface]


I was standing in the park, wondering why frisbees got bigger as they came closer... then it hit me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top