A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Import Excel file to array to fill ComboBox



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 14th 06, 08:42 PM posted to microsoft.public.outlook.program_forms
Pentoast
external usenet poster
 
Posts: 5
Default Import Excel file to array to fill ComboBox

I've been having a bit of trouble getting this to work. I have arrived
at the point where the combo box gets filled with the information, but
I'm not familiar enough with VBScript to figure out the rest. Here is
what I have so far:

Sub Item_Open()

Set FormPage = Item.GetInspector.ModifiedFormPages("More Info")
Set Control = FormPage.Controls("cboCategories")

On Error Resume Next
Set objXL = GetObject(, "Excel.Application")
Err.Clear
If objXL Is Nothing Then
Set objXL = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set Mybook = objXL.Workbooks.Add("C:\test\test.xls")
Mybook.Worksheets("Sheet1").Activate

MyVariable=objXL.Columns("a").Value

Set Mybook=Nothing
Set objXL=Nothing

Control.List() = MyVariable

End Sub


As you can tell, it loads all the information from Column A. The
problem is that it loads the ENTIRE column, not just the cells that are
filled. What can I do to filter out the empty cells?

Ads
  #2  
Old December 15th 06, 03:06 PM posted to microsoft.public.outlook.program_forms
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Import Excel file to array to fill ComboBox

What about defining a range that covers all the cells you want to import?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Pentoast" wrote in message oups.com...
I've been having a bit of trouble getting this to work. I have arrived
at the point where the combo box gets filled with the information, but
I'm not familiar enough with VBScript to figure out the rest. Here is
what I have so far:

Sub Item_Open()

Set FormPage = Item.GetInspector.ModifiedFormPages("More Info")
Set Control = FormPage.Controls("cboCategories")

On Error Resume Next
Set objXL = GetObject(, "Excel.Application")
Err.Clear
If objXL Is Nothing Then
Set objXL = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set Mybook = objXL.Workbooks.Add("C:\test\test.xls")
Mybook.Worksheets("Sheet1").Activate

MyVariable=objXL.Columns("a").Value

Set Mybook=Nothing
Set objXL=Nothing

Control.List() = MyVariable

End Sub


As you can tell, it loads all the information from Column A. The
problem is that it loads the ENTIRE column, not just the cells that are
filled. What can I do to filter out the empty cells?

  #3  
Old December 15th 06, 04:09 PM posted to microsoft.public.outlook.program_forms
Pentoast
external usenet poster
 
Posts: 5
Default Import Excel file to array to fill ComboBox

That would probably work better, but as I said before, I'm pretty new
at this, so I'm not too sure how to define the range that I need. I
tried this, but it didn't work.

MyVariable=objXL.Cells(1, 1).Cells(1, 10).Value

I'm just not sure what exactly to use. Any code or help will be
greatly appreciated. Thanks!



Sue Mosher [MVP-Outlook] wrote:
What about defining a range that covers all the cells you want to import?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


  #4  
Old December 15th 06, 04:25 PM posted to microsoft.public.outlook.program_forms
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Import Excel file to array to fill ComboBox

From Excel Help, this is the correct way to define a range with start and end points:

Worksheets("Sheet1").Range(Cells(1, 1), Cells(5, 3))

I was actually thinking of using an existing named range defined manually, though.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Pentoast" wrote in message ups.com...
That would probably work better, but as I said before, I'm pretty new
at this, so I'm not too sure how to define the range that I need. I
tried this, but it didn't work.

MyVariable=objXL.Cells(1, 1).Cells(1, 10).Value

I'm just not sure what exactly to use. Any code or help will be
greatly appreciated. Thanks!



Sue Mosher [MVP-Outlook] wrote:
What about defining a range that covers all the cells you want to import?


  #5  
Old December 15th 06, 04:48 PM posted to microsoft.public.outlook.program_forms
Pentoast
external usenet poster
 
Posts: 5
Default Import Excel file to array to fill ComboBox

how would I do what you were thinking?

  #6  
Old December 15th 06, 05:09 PM posted to microsoft.public.outlook.program_forms
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Import Excel file to array to fill ComboBox

Insert | Name | Define. You can then refer to the range by name. Details in Excel Help.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Pentoast" wrote in message ups.com...
how would I do what you were thinking?

  #7  
Old December 15th 06, 10:12 PM posted to microsoft.public.outlook.program_forms
Pentoast
external usenet poster
 
Posts: 5
Default Import Excel file to array to fill ComboBox

Ok, I figured that out and it works up to the point before the combobox
is populated by the information.

I get the error "Could not set the List property. Invalid property
Array Index." when it hits the line "Control.list() = MyArray"

I'm not sure how to properly index it.

  #8  
Old December 15th 06, 11:02 PM posted to microsoft.public.outlook.program_forms
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Import Excel file to array to fill ComboBox

Sounds like MyArray isn't an array, even though that's what you named it. Can you show the code snippet you use to get MyArray?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Pentoast" wrote in message ups.com...
Ok, I figured that out and it works up to the point before the combobox
is populated by the information.

I get the error "Could not set the List property. Invalid property
Array Index." when it hits the line "Control.list() = MyArray"

I'm not sure how to properly index it.

  #9  
Old December 18th 06, 03:06 PM posted to microsoft.public.outlook.program_forms
Pentoast
external usenet poster
 
Posts: 5
Default Import Excel file to array to fill ComboBox

oh... I'm sorry, I must have renamed it somewhere along the way just so
I could identify it better. It's actually in the code in the first
post. It is named "myVariable" in that code. Thanks!

  #10  
Old December 19th 06, 07:08 PM posted to microsoft.public.outlook.program_forms
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Import Excel file to array to fill ComboBox

It would be really helpful if you'd include the relevant information from previous messages. Unless you do, those of us using offline readers have to go back and retrieve the earlier part of the thread, which will delay any response.

Your statement

MyVariable=objXL.Columns("a").Value

does not return an array. This one does:

MyVariable=objXL.Columns("a")

However, it's an array generated from all 65536 cells in the column, probably not what you're looking for. You might want to use a named range or specify a range of specific cells you want to use.

Also, there are newsgroups specifically for Excel issues if you need more assistance on using things like Columns and Range.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Pentoast" wrote in message oups.com...
oh... I'm sorry, I must have renamed it somewhere along the way just so
I could identify it better. It's actually in the code in the first
post. It is named "myVariable" in that code. Thanks!

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I import Birthdays from an excel file? Bojana Outlook - Calandaring 0 September 6th 06 12:52 PM
How do I import an excel file into Outlook Calendar? Friarrico Outlook - Calandaring 1 June 21st 06 06:05 PM
How do I import an excel file into Calendar? Kent McLellan Outlook - Calandaring 2 June 7th 06 08:37 PM
excel file type missing from import a file window in outlook xanadufl Outlook - Using Contacts 9 February 28th 06 10:55 AM
Import an Excel file into Calendar Bobmeister Outlook - Calandaring 0 January 12th 06 08:36 PM


All times are GMT +1. The time now is 09:00 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.