Results 1 to 4 of 4

Thread: Excel VLookup in VB6

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    2

    Excel VLookup in VB6

    I am getting "The remote server machine does not exist or is unavailable"

    I am trying to access the VLookup function in my VB code (running as a COM+ component) to loopkup a range in excel file and update some data to database. The current sheet is Sheet1 and the range SRng is on Sheet2

    Set xlMyApp = CreateObject("Excel.Application")
    xlMyApp.Workbooks.Open ("BudFile.xls")
    xlMyApp.Workbooks(1).Application.DisplayAlerts = False
    .....
    .....
    Set rngSp = xlMyApp.Workbooks(1).Worksheets("Sheet2").Range("SRng")

    lsSpID = Application.VLookup(Trim(xlCell.Value), rngSp, 2, False)
    If IsError(lsSuppID) Or Trim(CStr(lsSpID)) = "" Then
    '.....do someting
    Else
    '....do something else
    End If

    Any solutions please.......

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Excel VLookup in VB6

    Welcome to VBForums!

    The problem is that you are using Application, rather than your applciation object variable (xlMyApp).

    A couple of other things.. using "xlMyApp.Workbooks(1).Application.DisplayAlerts" is a bit redundant - as .Application refers back to xlMyApp (ie: you could just do "xlMyApp.DisplayAlerts").

    Also, you are not using a variable for the Workbook, which is recommended (depending on settings, it is possible that your CreateObject wont create a new instance, but work with an existing one that already has books open). You can see examples of how to do this in my tutorial (link in my signature).

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    2

    Re: Excel VLookup in VB6

    Thank you...

    I tried using myXlApp.WorksheetFunction.VLookup but could not get to it. It throws an error.

    Is this function available elsewhere?

    Would myXlApp.Workbooks(1).Application.VLookup() give the same problem

    Could u please provide me a code snippet for the scenario.
    Last edited by skvabbili; Apr 24th, 2006 at 04:41 PM.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Excel VLookup in VB6

    I'm sure I've seen it done before, but I cant find the post

    The closest I could find was this alternative:
    http://www.vbforums.com/showthread.php?t=376315

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