Heavy interfacing with Excel in VB GUI

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adamrlee
    New Member
    • Jun 2008
    • 2

    Heavy interfacing with Excel in VB GUI

    I am trying to create a filter program in VB that will be able to heavily interface with a chosen Excel spreadsheet in XLS format. I was wondering if anyone could give me a better way to work with it instead of

    adding
    Public objExcel As New Excel.Applicati on
    under the class title and doing things like:

    ComboBox1.Items .Add(objExcel.R ange("a" & cell.ToString). Value.ToString)

    to add values to a comboBox.
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    sure
    remember that when you asign a range to a variant, the variant wont become a Variant/Range, but a 2 dimension array.

    if you asign a 2 dimension array to a combobox list property, the list will become the first column of this array, this way, if you do something like this

    [CODE=vb]dim Var1 as variant
    var1 = range("A1:J45")
    combobox1.list = var1[/CODE]

    then your combo box will have 45 elements: A1 to A45.

    Just make sure to call this range the right way, in the example below, i'll also use the END method as an easy way to call a range.

    [CODE=vb]with objExcel.worksh eets("sheet1")
    var1 = .range(.cells(1 ,1),.cells(1,1) .end(-4121))
    end with[/CODE]

    Note im using the xlDown parameter for the END method, but since there are no xl constants outside Excel's VBA, i had to use its numeric value: -4121

    HTH

    Comment

    Working...