3
votes

I am trying to import data from an Excel sheet into Word.

But I am failing pretty quickly. Word gets stuck right at the beginning.

My code is a simple as that:

Sub ImportDataFromExcel()

    Dim XLapp As Excel.Application

    Set XLapp = New Excel.Application    

End Sub

Here is what happens: Excel opens up. But Word freezes immediately. I have to force quit Word. Word would not get to any further line of code I had included. It stops at „Set XLapp = New Excel.Application“.

I tried a couple of things: I wrote similar code to open PowerPoint. That worked.

I wrote similar code into PowerPoint, to open Word from there. That worked.

I wrote the same code, that I posted here, into PowerPoint, to open Excel. That failed the same way!

And I also tried on a different Mac. Also there, same thing: Word freezes, when calling on Excel.

I am using Office 365 with Word and Excel for Mac, Version 16.24. As macro-reference in VBA I use the „Microsoft Excel 16.0 Object Library“. I am running MacOS Mojave (10.14.3) on my Mac.

Can anyone please help me?

2
Sorry for asking: How do I verifying the references?Florian
COM automation won't be available on Mac OS which is why it's crashing.Fink
So, you think, there is a solution?Florian
Simple answer is to use Office running on Windows if you want to do this sort of automation. Depending on what you're trying accomplish you could create an Excel output macro and a Word import macro.Fink

2 Answers

1
votes

I have no experience with this issue on Mac Os, but maybe rewriting the same code in a different way, will work. Try this:

Dim XLapp As New Excel.Application

Hope this helps.

0
votes

Try this please

Sub ImportDataFromExcel()

    Dim XLapp As Object

    Set XLapp = CreateObject("Excel.Application")

End Sub

Maybe MAC do not recoginized the excel library