troubleshooting Question

VBA - Getting Data from an Excel Worksheet and Creating a Collection of Custom (Book) objects

Avatar of FaheemAhmadGul
FaheemAhmadGulFlag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft Office.NET ProgrammingVBAMicrosoft ExcelMicrosoft Word
21 Comments1 Solution270 ViewsLast Modified:
In a simple VBA project for Word I have Class Module named Book which has just two properties - Title and Author - both strings.
I would like to be pull data from Sheet1 of a simple Excel Workbook to create a Collection of Books items ( named myBooks). Every book to be added to this Collection  (myBooks) will be created using a record from Sheet1 of the Excel Workbook, such that the value in Column 1 of each record will be the title of the Book and the value in Column 2 of each record will be the Author of the Book. I include a screen shot of the Sheet1 of my Excel Workbook.
Thank you for your help.

Screenshot of the Sheet1 of the Excel Workbook
Dim objExcel As New Excel.Application
Dim exWb As Excel.Workbook

Dim bookTitle As String
Dim bookAutor As String


Dim myBooks As Collection
Set myBooks = New Collection


Set exWb = objExcel.Workbooks.Open("G:\MyFolder\BookShelf.xlsx")


Set excelWorkBook = objExcel.Workbooks.Open("G:\Dr Ahmad\Handover\QuickWord.xlsx")

' I need code in this region which could run some kind of Loop on excelWorkBook  and give me a collection of book objects
' creating a book from all the records in Sheet1 of excelWorkBook such that the value in column 1 of each row will be the title of 
'  the book and the value in column 2 of each row will be the author of the book. 


exWb.Close

Set exWb = Nothing
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 21 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 21 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros