Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Export date from listbox to Excel


Reply
 
Thread Tools Display Modes
  #1  
Old 03-24-2003, 07:51 AM
Elik Elik is offline
Regular
 
Join Date: Mar 2003
Posts: 69
Question Export date from listbox to Excel


Could anyone help me to export date from listbox to Excel

Please help me!
Reply With Quote
  #2  
Old 03-24-2003, 09:06 AM
Wamphyri's Avatar
Wamphyri Wamphyri is offline
Variable not defined

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Ottawa, Ontario
Posts: 4,793
Default

Is this a listbox in a userform in excel or a listbox in a form outside of excel?
__________________
-Carl
Reply With Quote
  #3  
Old 03-24-2003, 09:26 AM
Elik Elik is offline
Regular
 
Join Date: Mar 2003
Posts: 69
Default

Quote:
Originally Posted by Wamphyri
Is this a listbox in a userform in excel or a listbox in a form outside of excel?




Listbox in a form outside of excel.
I need from within vb to export to excel some date which are in List1 and List2 bt never done something like this

Thanks in advance !
Reply With Quote
  #4  
Old 03-24-2003, 10:12 AM
Wamphyri's Avatar
Wamphyri Wamphyri is offline
Variable not defined

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Ottawa, Ontario
Posts: 4,793
Default

I'm assuming that you've never exported anything to Excel before.
So First thing. Add a reference to Microsoft's Excel Object Library.
Goto Projects -> References and choose Microsoft's Excel Object Library.

Enter the following code.
Code:
Dim xlApp As Excel.Application Dim xlSh As Excel.Worksheet Dim i As Long Set xlApp = New Excel.Application xlApp.Visible = True xlApp.Workbooks.Add Set xlSh = xlApp.Workbooks(1).Worksheets(1) For i = 1 To List1.ListCount xlSh.cells(i, 1).Value = List1.List(i - 1) Next Set xlSh = Nothing Set xlApp = Nothing
__________________
-Carl
Reply With Quote
  #5  
Old 03-24-2003, 10:56 AM
Elik Elik is offline
Regular
 
Join Date: Mar 2003
Posts: 69
Default

Quote:
Originally Posted by Wamphyri
I'm assuming that you've never exported anything to Excel before.
So First thing. Add a reference to Microsoft's Excel Object Library.
Goto Projects -> References and choose Microsoft's Excel Object Library.

Enter the following code.
Code:
Dim xlApp As Excel.Application Dim xlSh As Excel.Worksheet Dim i As Long Set xlApp = New Excel.Application xlApp.Visible = True xlApp.Workbooks.Add Set xlSh = xlApp.Workbooks(1).Worksheets(1) For i = 1 To List1.ListCount xlSh.cells(i, 1).Value = List1.List(i - 1) Next Set xlSh = Nothing Set xlApp = Nothing



Tank you Wamphyri this code runs fine
But How could I integrate the second Listbox(List2) here

Tanks in advance
Reply With Quote
  #6  
Old 03-24-2003, 11:17 AM
Elik Elik is offline
Regular
 
Join Date: Mar 2003
Posts: 69
Default

I have added the second list box Like bellow is it a righte decision?

Code:
Private Sub Command3_Click() Dim xlApp As Excel.Application Dim xlSh As Excel.Worksheet Dim i As Long Dim y As Long Set xlApp = New Excel.Application xlApp.Visible = True xlApp.Workbooks.Add Set xlSh = xlApp.Workbooks(1).Worksheets(1) For i = 1 To List1.ListCount xlSh.Cells(i, 1).Value = List1.List(i - 1) Next For y = 1 To List2.ListCount xlSh.Cells(y, 2).Value = List2.List(y - 1) Next Set xlSh = Nothing Set xlApp = Nothing End Sub

Last edited by Wamphyri; 03-24-2003 at 12:44 PM. Reason: Adding [vb] tags
Reply With Quote
  #7  
Old 03-24-2003, 12:46 PM
Wamphyri's Avatar
Wamphyri Wamphyri is offline
Variable not defined

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Ottawa, Ontario
Posts: 4,793
Default

Looks ok. The real test however is does it work the way you want it to?
__________________
-Carl
Reply With Quote
  #8  
Old 03-24-2003, 10:21 PM
Elik Elik is offline
Regular
 
Join Date: Mar 2003
Posts: 69
Default

Quote:
Originally Posted by Wamphyri
Looks ok. The real test however is does it work the way you want it to?



Oh! There is no problem with this code!
Reply With Quote
  #9  
Old 07-11-2003, 10:23 AM
erbartle erbartle is offline
Newcomer
 
Join Date: Jun 2003
Posts: 11
Default ListBox Related question

I have a form that contains a combobox and a list box. i want the contents of the listbox to change depending on what is selected in the combobox. I would want the listbox to be inactive (which I dont know how to do yet) untill a selection was made in the combobox. then at this point depending on what choice was made in the combobox a particular list would load into the listbox. what is the best way to do this?



Thanks a lot for the help.

Last edited by Wamphyri; 07-11-2003 at 10:34 AM. Reason: removed quote
Reply With Quote
  #10  
Old 07-11-2003, 10:34 AM
Wamphyri's Avatar
Wamphyri Wamphyri is offline
Variable not defined

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Ottawa, Ontario
Posts: 4,793
Default

The listbox you can set to Enabled = False initially
As for the listbox changing based on the selection in the combobox you can use a Select Case statement in the Change event of the Combobox
A small example
Code:
Private Sub ComboBox1_Change() ListBox1.Enabled = True Select Case ComboBox1.Text Case "Choice1" ListBox1.Clear ListBox1.AddItem "This" ListBox1.AddItem "That" Case "Choice2" ListBox1.Clear ListBox1.AddItem "Cat" ListBox1.AddItem "Dog" End Select End Sub
__________________
-Carl
Reply With Quote
  #11  
Old 07-11-2003, 10:49 AM
erbartle erbartle is offline
Newcomer
 
Join Date: Jun 2003
Posts: 11
Default

thanks a lot for the help.


is there anyway to pass variabes, in the case arrays, along with the form. when i initialized i put a bunch of values from a sheet into arrays in order to put them in the listbox and combobox. i want to pass them from the initializing routine to the combobox_change routine


Quote:
Originally Posted by Wamphyri
The listbox you can set to Enabled = False initially
As for the listbox changing based on the selection in the combobox you can use a Select Case statement in the Change event of the Combobox
A small example
Code:
Private Sub ComboBox1_Change() ListBox1.Enabled = True Select Case ComboBox1.Text Case "Choice1" ListBox1.Clear ListBox1.AddItem "This" ListBox1.AddItem "That" Case "Choice2" ListBox1.Clear ListBox1.AddItem "Cat" ListBox1.AddItem "Dog" End Select End Sub

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Export MSHFlexGrid To Excel verno_25_02 Word, PowerPoint, Outlook, and Other Office Products 0 03-12-2003 01:28 PM
export from flexgrid to excel daw General 8 08-28-2002 01:11 AM
Oracle Date in Excel tstbuddy Word, PowerPoint, Outlook, and Other Office Products 10 06-11-2002 08:10 AM
comparing dates with visual foxpro and ado azwaan General 8 01-08-2002 05:50 AM
Data collection, validation, and export to excel Dujenwook Database and Reporting 4 08-29-2001 06:52 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->