Hi all, I am new here.
Monthly, I get an email from my manager with cases in a table format. The columnns includes the case number, client name, date received, case type, remarks. The remarks cells is string data type and has a lot of carriage returns. What I usually do is do a find "^l" replace with "^v" but I would prefer to have a VBA code to automatically replaces all the carriage returns with a " ".
I found this code but there is an error "Method or data member not found" ini the For loop section wdCell.Range.Replace vbCr, "", wdReplaceAll. The word 'Replace' is the error.
Sub RemoveCarriageReturnsFromTable()
Dim olMail As MailItem
Dim wdDoc As Word.Document
Dim wdTable As Word.Table
Dim wdCell As Word.Cell
'Get the selected email
Set olMail = ActiveExplorer.Selection(1)
'Get the Word document that represents the email body
Set wdDoc = olMail.GetInspector.WordEditor
'Get the first table in the document
Set wdTable = wdDoc.Tables(1)
'Loop through each cell in the table
For Each wdCell In wdTable.Range.Cells
'Remove the carriage returns in the cell
wdCell.Range.Replace vbCr, "", wdReplaceAll
Next wdCell
End Sub
If you have better code would really help Thanks a lot
Monthly, I get an email from my manager with cases in a table format. The columnns includes the case number, client name, date received, case type, remarks. The remarks cells is string data type and has a lot of carriage returns. What I usually do is do a find "^l" replace with "^v" but I would prefer to have a VBA code to automatically replaces all the carriage returns with a " ".
I found this code but there is an error "Method or data member not found" ini the For loop section wdCell.Range.Replace vbCr, "", wdReplaceAll. The word 'Replace' is the error.
Sub RemoveCarriageReturnsFromTable()
Dim olMail As MailItem
Dim wdDoc As Word.Document
Dim wdTable As Word.Table
Dim wdCell As Word.Cell
'Get the selected email
Set olMail = ActiveExplorer.Selection(1)
'Get the Word document that represents the email body
Set wdDoc = olMail.GetInspector.WordEditor
'Get the first table in the document
Set wdTable = wdDoc.Tables(1)
'Loop through each cell in the table
For Each wdCell In wdTable.Range.Cells
'Remove the carriage returns in the cell
wdCell.Range.Replace vbCr, "", wdReplaceAll
Next wdCell
End Sub
If you have better code would really help Thanks a lot