It is 1 based, not zero based.Quote:
Originally Posted by RobDog888
Printable View
It is 1 based, not zero based.Quote:
Originally Posted by RobDog888
Posted you code in my program and it worked perfectly.
Maybe its the file you are trying to open? Try another.
VB Code:
Private Sub bOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bOpenFile.Click Dim oExcel As Object Dim oWorkBook As Excel.Workbook Dim oWorkSheet As Excel.Worksheet oExcel = CType(CreateObject("Excel.application"), Excel.Application) oExcel.Visible = True oWorkBook = CType(oExcel.Workbooks.Open("J:\Documents and Settings\DavidH\My Documents\Blank.xls"), Excel.Workbook) oWorkSheet = CType(oWorkBook.Worksheets.Item(2), Excel.Worksheet) oWorkSheet.Activate() End
There has to be something else going on here...
Not sure what, so Ill have to do some more digging...
I got this code to work when i created a new project. It still doesnt work on my original one, any ideas why?
Private Sub bopen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bopen.Click
Dim oExcel As Object
Dim oWorkBook As Excel.Workbook
Dim oWorkSheet As Excel.Worksheet
oExcel = CType(CreateObject("Excel.application"), Excel.Application)
oExcel.Visible = True
oWorkBook = CType(oExcel.Workbooks.Open("C:\documents and settings\mike\desktop\dss.xls"), Excel.Workbook)
oWorkSheet = CType(oWorkBook.Worksheets.Item(4), Excel.Worksheet)
oWorkSheet.Activate()
End Sub
My mistake. Confused Items with Sheets. :blush:Quote:
Originally Posted by PENNYSTOCK
ok, give up now. Going to use excel and vba instead (which is bound to cause me more problems!!!)
Cheers for your help guys
Can you compare your projects side by side for differences in references, code lines, etc.?
I think the problem was that the original excel book i was opening was pre used and contained un-deleted macros. Whereas the new workbook i tried didnt and worked fine