Your code works at my side.
The "run-time error ‘4198’: Command failed" error message usually occurs when there is an issue with the clipboard.
You may try this one.
wdDoc.Range(Len(strGreeting), Len(strGreeting)).PasteSpecial DataType:=wdPasteText
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Sub MACRO_NAME_Email()
Sheets("Email").Select
Dim olApp As Outlook.Application
Dim olEmail As Outlook.MailItem
Dim ilInsp As Outlook.Inspector
Dim wdDoc As Word.Document
Dim strGreeting As String
Dim strClosing As String
Set olApp = New Outlook.Application
Set olEmail = olApp.CreateItem(olMailItem)
With olEmail
.BodyFormat = olFormatHTML
.Display
.To = ThisWorkbook.Sheets("Email").Range("D2").Value
.CC = ThisWorkbook.Sheets("Email").Range("D3").Value
.Subject = ThisWorkbook.Sheets("Email").Range("D4").Value
Set olInsp = .GetInspector
Set wdDoc = olInsp.WordEditor
wdDoc.Range.InsertAfter strGreeting
Sheets("Email").Select
Range("D5:I75").Copy
wdDoc.Range(Len(strGreeting), Len(strGreeting)).Paste
End With
End Sub
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Your code works at my side.
The "run-time error ‘4198’: Command failed" error message usually occurs when there is an issue with the clipboard.
You may try this one.
wdDoc.Range(Len(strGreeting), Len(strGreeting)).PasteSpecial DataType:=wdPasteText
You may try adding these lines.
=========================
Set olEmail = Nothing
Set olApp = Nothing
Set ilInsp = Nothing
Set wdDoc = Nothing
This will release all the set objects and free up memory resources.