By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,959 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,959 IT Pros & Developers. It's quick & easy.

Heavy interfacing with Excel in VB GUI

P: 2
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

Public objExcel As New Excel.Application
under the class title and doing things like:

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

to add values to a comboBox.
Jun 6 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,295
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

Expand|Select|Wrap|Line Numbers
  1. dim Var1 as variant
  2. var1 = range("A1:J45")
  3. combobox1.list = var1
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.

Expand|Select|Wrap|Line Numbers
  1. with objExcel.worksheets("sheet1")
  2.     var1 = .range(.cells(1,1),.cells(1,1).end(-4121))
  3. end with
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

Jun 6 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.