Dear forum members. This time I would like to solve this problem but I am blocked. I want to make a listbox work in a form made in word but the information is in an excel book, if possible without opening it.
For this I have:
My Word document in a folder
An excel book in the same folder, Name: GENTEST.xlsm
The sheet I require is Sheet5, Name: Bibliography
The columns that I want to be in the Listbox are: A and B until the last row with data
the code i have been testing is this:
HTML Code:
Sub cargarlistbox()
Dim xlApp As Object
Dim xlWB As Object
Dim xlWS As Object
Dim cRows As Long
Dim i As Long
Set xlApp = GetObject(, "Excel.Application")
Set xlWB = xlApp.Workbooks.Open("C:\Users\PC\Documents\RESPALDO\PROGRAM\WORD\TAXONOMIA\GENTEST.xlsm")
Set xlWS = xlWB.Worksheets(5)
cRows = xlWS.Range("Bibliografia").Rows.Count - xlWS.Range("Bibliografia").Row + 1
ListBox1.ColumnCount = 2
With Me.ListBox1
For i = 2 To cRows
.AddItem xlWS.Range("Bibliografia").Cells(i, 1)
.List(.ListCount - 1, 1) = xlWS.Range("Bibliografia").Cells(i, 2)
Next i
End With
Set xlWS = Nothing
Set xlWB = Nothing
xlApp.Quit
Set xlApp = Nothing
lbl_Exit:
Exit Sub
End Sub
I appreciate your kind support for this issue