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
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