Results 1 to 3 of 3

Thread: Link to a paricular worksheet [Resolved]

  1. #1

    Thread Starter
    Addicted Member haihems's Avatar
    Join Date
    Oct 2004
    Posts
    150

    Resolved 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

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    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."

  3. #3

    Thread Starter
    Addicted Member haihems's Avatar
    Join Date
    Oct 2004
    Posts
    150

    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
  •  



Click Here to Expand Forum to Full Width