|
-
Jan 30th, 2013, 04:45 AM
#16
Thread Starter
Member
Re: Adding and removing data from a list box using a command button in VB 6
Ok no that change didnt make any difference. The short program Im running just to test this code is a simple form with a list box and 2 command buttons.
Here's the exact code I'm using to try run it. Clicking command 1 should display the excel information and then on clicking command 2 the excel info should be replaced by 'Good By' 'Adios'. Is this correct?
Dim oExcel As Excel.Application
Dim wkbObj As Excel.Workbook
Dim oSheet As Excel.Worksheet
Private Sub Command1_Click()
List1.Clear
Set wkbObj = GetObject(App.Path & "F:\Machine info for HQ and FQ Shrink Tunnel.xlsx") '''Where 'myExcelFileName' contains the path to your excel file and the name itself (e.g, app.path & "\myExcel.xlsx"
'''followed by something like this:
Dim i As Integer, numrows As Integer
numrows = wkbObj.Worksheets(1).Range("A1").CurrentRegion.Rows.Count
For i = 1 To numrows
List1.AddItem (wkbObj.Worksheets(1).Range("A" & i + 1).Value) 'where "A" is the column you want loaded
'''Note the 'i + 1'---use the '+ 1" IF your Excel first row contains headers you don't want in the listbox, otherwise, just use 'i'
Next i
End Sub
Private Sub Command2_Click()
List1.Clear
List1.AddItem ("Good by")
List1.AddItem ("Adios")
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|