Create Excel spreadsheet from Word using VBA

I'm trying to create an Excel spreadsheet and populate it with data from Word, but I can't get VBA to follow through. It launches Excel, but then it errors out.

If I try early binding, such as with this code from the Microsoft Documentation, I get a Run-time error '13': Type mismatch on the Set xlApp line.

Sub test()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
End Sub

If I try late binding, I get a Run-time error '438': Object doesn't support this property or method on the Set xlBook line

Sub test()
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
End Sub

Many people throughout StackOverflow use variations of this successfully. I can't figure out why it doesn't work for me. One user on StackOverflow reported that the problem only persisted on their Mac. If it is a platform problem, is there a way to fix it so it will work on my Mac?



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation