Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

Populate lstWorksheet (list box) with all worksheets present in file "C:\MyFolder\Budget.xls"

Dim FileName As String
Dim WorkshettVar As String
FileName= "C:\MyFolder\Budget.xls"

lstWorksheet.Clear
.
.<code to cycle through Worksheet names in FileName excel file to store it in variable "WorkshettVar " >
.
lstWorksheet.AddItem = WorkshettVar

This lstWorksheet (list box) is on a VB 6 form.  It will be called from VB.

Thanks
SOLUTION
Avatar of JustinCase2
JustinCase2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of byundt
byundt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Eghtebas

ASKER

Thank you all for the good responses.  They helped me to come up with:

Dim xlApp As New Excel.Application
Dim xlWkBk As Excel.Workbook
Dim xlWkSht As Excel.Worksheet

Set xlWkBk = xlApp.Workbooks.Open("C:\MyFolder\Test.xls")
Set xlWkSht = xlWkBk.Worksheets("Sheet1")

For Each ws In ActiveWorkbook.Worksheets
    MsgBox  ws.Name
Next ws

Set xlWkSht = Nothing
xlWkBk.Close
Set xlWkBk = Nothing
xlApp.Quit
Set xlApp = Nothing

Mike