|
-
Dec 15th, 2004, 04:14 AM
#1
Thread Starter
Addicted Member
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.
Last edited by haihems; Dec 15th, 2004 at 08:55 PM.
Reason: Resolved
-
Dec 15th, 2004, 04:24 AM
#2
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
"The dark side clouds everything. Impossible to see the future is."
-
Dec 15th, 2004, 08:55 PM
#3
Thread Starter
Addicted Member
Thanks
Hi Jorge,
Thanks for ur immediate reply. I've tried the code, it works perfect.
Regards,
Hems.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|