Excel Mac VBA Export to Word

AdamPickard

New Member
Joined
Jul 6, 2015
Messages
14
Hello everyone, I have come across a problem that has not been resolved elsewhere.

Like most on the forum, I am not a coder and all of my VBA is made from adjusting code that other people have created. I recently updated my Mac from High Sierra to Big Sur 11.6. I was using Microsoft Office Mac 2011 but I had to upgrade this as Mac 2011 no longer works on more recently operating systems. The current version of office is Microsoft Office 2021 version 16.54.

The code selects a range of cells in Excel, copys them, opens up Microsoft Word, pastes them then converts the table to text. Here is the code that works perfectly fine on Microsoft Office Mac 2011:

Sub ExportToWord2()
Dim wdApp As Object, wdDoc As Object, wdRng As Object
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDoc = wdApp.Documents.Add
Sheets("TextForReport").Range("B39:B450").Copy
Set wdRng = wdDoc.Range
With wdRng
.Collapse Direction:=0 'wdCollapseEnd
.Paste
.End = .Tables(1).Range.End + 1
.Tables(1).ConvertToText 1 'wdSeparateByTabs
With .ParagraphFormat
.SpaceAfter = 0
.SpaceBefore = 0
End With
End With

wdApp.Visible = True
End Sub

Through running the debug line by line the issue seems to be at the '.paste' part. I do not get an error code as Excel just completely crashes and I have to Force Quit.

Does anyone know how to fix this? I will be eternally grateful if anyone can help!

Many thanks,

Adam
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Further update. I found this thread that has some similarities with my issue:


Sub CopyToWord()

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''Create Word Doc
Dim oWord As Object
Application.Wait (10)
DoEvents
Set oWord = CreateObject(Class:=("Word.application"))
Application.Wait (10)
DoEvents
oWord.Visible = True
oWord.Activate
Application.Wait (10)
DoEvents
Dim oDoc
Application.Wait (10)
DoEvents
Set oDoc = oWord.Documents.Add

'Copy To Word
Sheet23.Select
Range("Print_Area21").CopyPicture
oWord.Application
oWord.Application.Selection.Paste.Special Link:=False, DataType:=15, _
DisplayAsIcon:=False
oWord.Selection.TypeParagraph


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''End Message
MsgBox ("Compied to Word")

End Sub

I tried using this code instead (with modifying the copy part to Sheets("TextForReport").Range("B39:B450").Copy). I then ran the code line by line and it still again crashes at .paste
 
Upvote 0
Mac Office 2011 ran its apps without placing them in a sandbox. Since then Apple requires apps to run in a sandbox so that one app can't take down the system. When Microsoft designed the next version of Mac Office, rather than running all of Office in one sandbox, they run each app in its own sandbox. So Excel can't reach out of its sandbox into the Word sandbox, and so you can't use VBA to automate Word or PowerPoint. When I build this functionality for clients lately, I tell them that it only works in Windows.
 
Upvote 0
Hello Jon,

Thank you very much for taking the time to read through this! I did indeed come across all of the things you mentioned. I have managed to make a little progress that you might find interesting (and might lead you to be able to help me find a solution).

If I run the code and leave it for 1-2 minutes, it will actually copy and paste all of the data from Excel to Word. This message pops up: 'Microsoft Excel is waiting for another application to complete an OLE action.'

I just need to know why it takes 1-2 minutes to load and what I can do to fix this? The code literally ran instantly on MS Office 2011.

Any ideas?

Many thanks,

Adam
 
Upvote 0
I know it ran instantly in Mac Office 2011, in fact, it ran faster than in Windows Office 2013.

I spent a lot of time trying to get this to work in Mac Office 2016 and later. Sometimes it would work, but usually it just waited a long long time (waiting for another application...). I think this is one of the few places where Mac Office and especially VBA is just never going to be on par with Windows.
 
Upvote 0
I am able to reproduce the problem. I reported this issue to Microsoft today.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,559
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top