Search code examples
vbaoutlookms-word

VBA find/replace code .Execute Replace:=wdReplaceAll is not working


I am working on export Outlook email able date to excel sheet. But encountered .Execute Replace:=wdReplaceAll error. I have enabled necessary


Solution

  • Problem resolved with below code

     Set xExcelApp = CreateObject("Excel.Application")
    Set xWb = xExcelApp.Workbooks.Open(mypath)
    xExcelApp.Visible = True
    Set xWs = xWb.Sheets("Sheet1")
     xWs.Activate
    Set oLookwordTbl = oLookWordDoc.Tables(1)    'Grab the word table
    colcount = oLookwordTbl.Columns.Count
    For iRow = 2 To oLookwordTbl.Rows.Count         
     'oLookwordTbl.Rows(iRow).Range.Copy
        For icol = 1 To colcount
            cellvalue = oLookwordTbl.Cell(iRow, icol)
            cellvalue = Replace(cellvalue, Chr(13), "")
            cellvalue = Replace(cellvalue, Chr(10), "")
            cellvalue = Replace(cellvalue, Chr(244), "")
            cellvalue = Replace(cellvalue, "^p", "")
            cellvalue = Left(cellvalue, Len(cellvalue) - 1)
            xWs.Cells(iRow, icol).Value = cellvalue
        Next
    Next
    xWs.Cells(xWs.Rows.Count, 1).End(3).Offset(1).Select
    End Sub