Link to a paricular worksheet [Resolved]
Hai all,
I'm trying to link excel from vb.net to do data read & write. I'm able to do the linking but my problem is, i can't conncet to a particular worksheet.
This is my coding....
Code:
Dim oExcel As New Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim R1 As Excel.Range
oBook = oExcel.Workbooks.Open("c:\temp\new1.xls")
oSheet = oBook.Worksheets("first") ' 3 worksheets 1.First, 2.Second, 3.Third
oSheet.Range("A2").Value = Label1.Text
oExcel.Range("C8:D19").Select()
R1 = oExcel.Selection
For i = 1 To 12
For j = 1 To 2
R1(i, j).value = Txtp(i,j).Text
Next
Next
oBook.Save()
oBook.Close()
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
In my above coding label's value is moved to my "first" worksheet...but the the text array value are not moved to the "first" worksheet. It goes to the active worksheet (which is "third").
I know that it is bcos of Oexcel.selection...i tried as osheet.selection but error occoured...dont know what to do????
I'm stucking with this...anybody can help me???
I appreciate the quick response...
Thanks in advance
Regards,
Hems.
Re: Link to a paricular worksheet
Hi
You need to use .activate method to select a sheet.
This how i do it , i have option strict on .
Code:
DirectCast(Book.Sheets("First"), Excel.Worksheet).Activate()
Sheet = DirectCast(Book.ActiveSheet, Excel.Worksheet)
Regards
Jorge