Results 1 to 4 of 4

Thread: Validation in Combo From other WorkBook

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Validation in Combo From other WorkBook

    Dear All,
    i am using Ms office 2003

    i was reading site

    http://www.contextures.com/xlDataVal11.html


    === modified code ========

    Code:
    Option Explicit
    
    Private Sub TempCombo_KeyDown(ByVal _
            KeyCode As MSForms.ReturnInteger, _
            ByVal Shift As Integer)
        'Hide combo box and move to next cell on Enter and Tab
        Select Case KeyCode
            Case 9
                ActiveCell.Offset(0, 1).Activate
            Case 13
                ActiveCell.Offset(1, 0).Activate
            Case Else
                'do nothing
        End Select
    
    End Sub
    
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim str As String
    Dim cboTemp As OLEObject
    Dim ws As Worksheet
    Dim wsList As Worksheet
    Dim oXl As Application
    
    
    Set oXl = CreateObject("Excel.Application")
    oXl.Visible = False
    oXl.Workbooks.Open ("C:\import_data.xls")
    Set wsList = Sheets("DataList")
    Cancel = True
    Set cboTemp = ws.OLEObjects("TempCombo")
      On Error Resume Next
      With cboTemp
        .ListFillRange = ""
        .LinkedCell = ""
        .Visible = False
      End With
    On Error GoTo errHandler
      If Target.Validation.Type = 3 Then
        Application.EnableEvents = False
        str = Target.Validation.Formula1
        str = Right(str, Len(str) - 1)
        With cboTemp
          .Visible = True
          .Left = Target.Left
          .Top = Target.Top
          .Width = Target.Width + 15
          .Height = Target.Height + 5
          .ListFillRange = str
          .LinkedCell = Target.Address
        End With
        cboTemp.Activate
      End If
      
    errHandler:
      Application.EnableEvents = True
      Exit Sub
    
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim str As String
    Dim cboTemp As OLEObject
    Dim ws As Worksheet
    Set ws = ActiveSheet
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    
    If Application.CutCopyMode Then
      'allows copying and pasting on the worksheet
      GoTo errHandler
    End If
    
    Set cboTemp = ws.OLEObjects("TempCombo")
      On Error Resume Next
      With cboTemp
        .Top = 10
        .Left = 10
        .Width = 0
        .ListFillRange = ""
        .LinkedCell = ""
        .Visible = False
        .Value = ""
      End With
    
    errHandler:
      Application.ScreenUpdating = True
      Application.EnableEvents = True
      Exit Sub
    
    End Sub

    what i want to is, i want to us Another WorkBook and use the values to Combo box


    can anyone help me pls

    error : Subscript out of range

    Set wsList = Sheets("DataList")


    import_data.xls has this worksheet

    Thanks
    Last edited by skaswani; Jan 26th, 2009 at 12:53 PM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Validation in Combo From other WorkBook

    If "DataList" is in a different workbook then preface the whole thing with the workbook name.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Re: Validation in Combo From other WorkBook

    changed
    ====

    Set wsList = oXl.Sheets("DataList")

    ===

    now error on

    Set cboTemp = ws.OLEObjects("TempCombo")


    error:
    Object variable or with block variable not set

  4. #4
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Validation in Combo From other WorkBook

    You haven't set ws to be anything. Notice how in the SelectionChange sub it has been set to ActiveSheet...?
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

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