Share via

Run-Time Error 4198 "Command Failed"

Anonymous
2023-09-20T16:18:31+00:00

Sub SendMail()

Dim OutApp As New Outlook.Application

Dim Mail As Outlook.MailItem

Dim Doc As Word.Document

'Dim R As Integer

If (Sheet4.AutoFilterMode = True) Then

Sheet4.AutoFilterMode = False

End If

'For R = 2 To Sheet10.Cells(Rows.Count, 1).End(xlUp).Row

Set Mail = OutApp.CreateItem(olMailItem)

With Mail

.BodyFormat = olFormatHTML

.Display

.To = Sheet10.Range("F2").Value2

.CC = Sheet10.Range("G2").Value2

.Subject = "Week Till Date Performance"

Set Doc = .GetInspector.WordEditor

Doc.Range = "Dear Seller, " & vbNewLine & _

"Please find below the data for your week till date performance. This includes your sales, visibility, brokenness, returns, etc.:" & vbNewLine & vbNewLine

Doc.Range.Characters.Last.Text = vbNewLine

Sheet4.Range("A1").CurrentRegion.AutoFilter _

Field:=6, \_ 

Criteria1:=Sheet10.Range("A2").Value2 

Sheet4.Range("A1").CurrentRegion.SpecialCells(xlCellTypeVisible).Copy

Doc.Range.Characters.Last.Paste (Getting the error here)

Application.CutCopyMode = False

Doc.Range.Characters.Last.Text = vbNewLine & vbNewLine & _

"Best Regard," & vbNewLine & _

"Mohd Shahid Deshnoor"

End With

End Sub

Microsoft 365 and Office | Excel | For business | Windows

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.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-09-20T17:20:16+00:00

    The error message "Run time error 4198" indicates that there is a problem with the clipboard. This error can occur if there is no data on the clipboard or if the data on the clipboard is not compatible with the application.

    To resolve this issue, you can try copying some data to the clipboard manually and then running the code again. Alternatively, you can try using the PasteSpecial method instead of the Paste method to paste the data.

    Here is an example of how to use the PasteSpecial method:

    =========================================

    Doc.Range.Characters.Last.PasteSpecial DataType:=wdPasteText

    ==========================================

    Was this answer helpful?

    0 comments No comments